记录编号 |
203675 |
评测结果 |
EEEEE |
题目名称 |
平凡的皮卡丘 |
最终得分 |
0 |
用户昵称 |
slyterlins |
是否通过 |
未通过 |
代码语言 |
C++ |
运行时间 |
0.877 s |
提交时间 |
2015-11-03 14:49:58 |
内存使用 |
0.62 MiB |
显示代码纯文本
- #include<iostream>
- #include<cstdio>
- #include<algorithm>
- #include<cstdlib>
- #include<cstring>
- #include<vector>
- #include<queue>
- using namespace std;
- int n,m,ans,maxx,from,now,pre;
- struct edge{
- int to,l;
- };
- vector<edge>p[40050];
- inline void dfs(){
- for(int i=0;i<p[now].size();i++)
- if(p[now][i].to!=pre){
- if(p[now][i].to==1){
- ans+=p[now][i].l;
- if(maxx!=0)maxx=min(maxx,ans);
- else maxx=ans;
- // cout<<ans<<endl;
- return;
- }
- else {
- ans+=p[now][i].l;
- // cout<<now<<' '<<p[now][i].l<<' '<<ans<<endl;
- int xx=pre;
- pre=now;
- now=p[now][i].to;
- dfs();
- now=pre;ans-=p[now][i].l;
- pre=xx;
- }
-
-
- }
- }
-
- int main()
- {
- freopen("both.in","r",stdin);
- freopen("both.out","w",stdout);
- cin>>n>>m;
- for(int i=1;i<=m;i++){
- int a,b,c,d;
- cin>>a>>b>>c>>d;
- p[a].push_back((edge){b,c});
- p[b].push_back((edge){a,d});
- }
- pre=1;now=1;
- dfs();
- if(maxx==0)cout<<0-1;
- else cout<<maxx;
- }