Guest User

Untitled

a guest
Aug 15th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. vector<vector<int>>v(160),r(160);
  5. int vis[10005],num[160],f[160],low[160],T;
  6. vector<int>top,tt;
  7. typedef long long ll;
  8. vector<pair<int,int>>p[10005];
  9. ll dfs(int n,int fr)
  10. {
  11. vis[n]=1;
  12. ll t=0;
  13. for(int i=0;i<p[n].size();i++)
  14. {
  15.  
  16. if(!vis[p[n][i].first]){
  17. // if(p[n][i].first!=fr)
  18.  
  19. t=max(dfs(p[n][i].first,n)+p[n][i].second,t);
  20. }
  21. }
  22. return t;
  23. }
  24.  
  25. char ss[30];
  26. int main()
  27. {
  28.  
  29. ll n,m,c,ma=0;
  30. bool ok=1;
  31. while(ok)
  32. {
  33. int zz=0;
  34. // memset(vis,0,sizeof(vis));
  35.  
  36. //if(a==0&&b==0&&c==0)break;
  37. for(int i=0;i<=10001;i++)
  38. {
  39. p[i].clear();
  40. }
  41. while(1){
  42. if(gets(ss)==0)
  43. {
  44. ok=0;
  45. break;
  46. }
  47. if(ss[0]) {
  48. int a,b;
  49. sscanf(ss, "%d%d%d", &a, &b, &c);
  50. zz=max({zz,b,a});
  51. p[a].push_back(make_pair(b,c));
  52. p[b].push_back(make_pair(a,c));
  53. }
  54. else break;
  55. }
  56.  
  57.  
  58. for(int i=1;i<=zz;i++)
  59. {
  60. ma=max(ma,dfs(i,0));
  61. memset(vis,0,sizeof(vis));
  62. }
  63.  
  64.  
  65. cout<<ma<<endl;;
  66. ma=0;
  67. }
  68. return 0;
  69. }
Add Comment
Please, Sign In to add comment