比赛 |
noip2016普及练习2 |
评测结果 |
|
题目名称 |
保卫钓鱼岛! |
最终得分 |
0 |
用户昵称 |
jjky |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2016-11-07 21:12:36 |
显示代码纯文本
- #include<cstdio>
- #include<cstdlib>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- #include<map>
- #include<queue>
- #include<vector>
- using namespace std;
- const int maxn=10010,maxm=100010;
- int head[maxn],cn,n,m,sum,num;
- bool flag;
- long long he;
- struct date
- {
- int to,next;
- long long co;
- }edge[maxm];
- void addedge(int a,int b,int c)
- {
- edge[cn].to=b;
- edge[cn].next=head[a];
- edge[cn].co=c;
- head[a]=cn++;
- }
- int read()
- {
- int x=0;
- char ch;
- ch=getchar();
- while(ch<'0'||ch>'9')
- ch=getchar();
- while(ch>='0'&&ch<='9')
- {
- x=x*10+ch-'0';
- ch=getchar();
- }
- return x;
- }
- void dfs(int cur,int v,long long cost)
- {
- if(cur==v)
- {
- flag=1;
- sum=cost;
- return ;
- }
- int i,to,c;
- for(i=head[cur];i!=-1;i=edge[i].next)
- {
- to=edge[i].to;
- c=edge[i].co;
- if(flag==1)
- return ;
- dfs(to,v,cost+c);
- }
- return ;
- }
- int main()
- {
- freopen("diaoyu.in","r",stdin);
- freopen("diaoyu.out","w",stdout);
- int a,b,t,u,v;
- n=read();m=read();
- memset(head,-1,sizeof(head));
- for(int i=1;i<n;i++)
- {
- a=read();b=read();t=read();
- addedge(a,b,t);
- }
- for(int i=1;i<=m;i++)
- {
- u=read();v=read();
- flag=0;
- sum=0;
- dfs(u,v,0);
- if(flag==1)
- {
- num++;
- he+=sum;
- }
- }
- printf("%d\n%d",num,he);
- }
- /*
- 6 2
- 1 2 1
- 2 4 1
- 2 5 1
- 5 6 1
- 1 3 1
- 2 6
- 4 5
-
- 1
- 2
- */
-