比赛 |
noip2016普及练习2 |
评测结果 |
|
题目名称 |
保卫钓鱼岛! |
最终得分 |
0 |
用户昵称 |
Furyton |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2016-11-07 21:06:58 |
显示代码纯文本
- #include <iostream>
- #include <cstdio>
- #include <climits>
- #include <cstring>
- #include <algorithm>
- using namespace std;
- //longint
- const int maxn=10000+1;
- struct node
- {
- int x,y,t;
- }table[maxn*2];
- node father[maxn];
- long long int cnt,ans,timeuse,tmp;
- int u,v,n,m;
- int main()
- {
- freopen("diaoyu.in","r",stdin);
- freopen("diaoyu.out","w",stdout);
-
- cin>>n>>m;
- for(int i=1; i<=n; i++)
- father[i].x=-1;
- for(int i=1; i<n; i++)
- {
- int a,b,c;
- cin>>a>>b>>c;
- father[b].x=a; father[b].t=c;
- }
- while(m--)
- {
- cin>>u>>v;
- if(u==v)
- {
- continue;
- }
- int x=v;
- bool flag=false; cnt=0,tmp=0;
- while(x>0)
- {
- if(x==u) {flag=true;cnt--;break;}
- tmp+=father[x].t;cnt++;
- x=father[x].x;
- }
- if(flag)
- {
- ans+=cnt; timeuse+=tmp;
- }
- }
- cout<<ans<<endl;
- cout<<timeuse<<endl;
- return 0;
- }