比赛 noip2016普及练习2 评测结果
题目名称 保卫钓鱼岛! 最终得分 0
用户昵称 Furyton 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2016-11-07 21:06:58
显示代码纯文本
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <climits>
  4. #include <cstring>
  5. #include <algorithm>
  6. using namespace std;
  7. //longint
  8. const int maxn=10000+1;
  9. struct node
  10. {
  11. int x,y,t;
  12. }table[maxn*2];
  13. node father[maxn];
  14. long long int cnt,ans,timeuse,tmp;
  15. int u,v,n,m;
  16. int main()
  17. {
  18. freopen("diaoyu.in","r",stdin);
  19. freopen("diaoyu.out","w",stdout);
  20.  
  21. cin>>n>>m;
  22. for(int i=1; i<=n; i++)
  23. father[i].x=-1;
  24. for(int i=1; i<n; i++)
  25. {
  26. int a,b,c;
  27. cin>>a>>b>>c;
  28. father[b].x=a; father[b].t=c;
  29. }
  30. while(m--)
  31. {
  32. cin>>u>>v;
  33. if(u==v)
  34. {
  35. continue;
  36. }
  37. int x=v;
  38. bool flag=false; cnt=0,tmp=0;
  39. while(x>0)
  40. {
  41. if(x==u) {flag=true;cnt--;break;}
  42. tmp+=father[x].t;cnt++;
  43. x=father[x].x;
  44. }
  45. if(flag)
  46. {
  47. ans+=cnt; timeuse+=tmp;
  48. }
  49. }
  50. cout<<ans<<endl;
  51. cout<<timeuse<<endl;
  52. return 0;
  53. }