记录编号 203675 评测结果 EEEEE
题目名称 平凡的皮卡丘 最终得分 0
用户昵称 Gravatarslyterlins 是否通过 未通过
代码语言 C++ 运行时间 0.877 s
提交时间 2015-11-03 14:49:58 内存使用 0.62 MiB
显示代码纯文本
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstdlib>
  5. #include<cstring>
  6. #include<vector>
  7. #include<queue>
  8. using namespace std;
  9. int n,m,ans,maxx,from,now,pre;
  10. struct edge{
  11. int to,l;
  12. };
  13. vector<edge>p[40050];
  14. inline void dfs(){
  15. for(int i=0;i<p[now].size();i++)
  16. if(p[now][i].to!=pre){
  17. if(p[now][i].to==1){
  18. ans+=p[now][i].l;
  19. if(maxx!=0)maxx=min(maxx,ans);
  20. else maxx=ans;
  21. // cout<<ans<<endl;
  22. return;
  23. }
  24. else {
  25. ans+=p[now][i].l;
  26. // cout<<now<<' '<<p[now][i].l<<' '<<ans<<endl;
  27. int xx=pre;
  28. pre=now;
  29. now=p[now][i].to;
  30. dfs();
  31. now=pre;ans-=p[now][i].l;
  32. pre=xx;
  33. }
  34. }
  35. }
  36.  
  37. int main()
  38. {
  39. freopen("both.in","r",stdin);
  40. freopen("both.out","w",stdout);
  41. cin>>n>>m;
  42. for(int i=1;i<=m;i++){
  43. int a,b,c,d;
  44. cin>>a>>b>>c>>d;
  45. p[a].push_back((edge){b,c});
  46. p[b].push_back((edge){a,d});
  47. }
  48. pre=1;now=1;
  49. dfs();
  50. if(maxx==0)cout<<0-1;
  51. else cout<<maxx;
  52. }