fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const long long N=1e5+3,big=1e18,mod=1e9+7;
  5.  
  6. vector<long long > a[N];
  7. long long depth[N],parent[N][18],dist[N][18];
  8. long long n,x,w,y;
  9. void dfs(long long i,long long p)
  10. {
  11. for(int j=0;j<a[i].size();j++)
  12. if(a[i][j]!=p)
  13. {
  14. parent[a[i][j]][0]=i;
  15. depth[a[i][j]]=depth[i]+1;
  16. dist[a[i][j]][0]=a[i][j].second;
  17. dfs(a[i][j],i);
  18. }
  19. }
  20. int main()
  21. {
  22. cin>>n;
  23. for(int i=0;i<n-1;i++)
  24. {
  25. cin>>x>>y;
  26. a[x].push_back(y);
  27. a[y].push_back(x);
  28. }
  29. memset(parent,-1,sizeof(parent));
  30. memset(dist,-1,sizeof(dist));
  31. dfs(1,0);
  32. for(int j=0;j<=17;j++)
  33. parent[1][j]=-1;
  34.  
  35. for(int j=1;j<18;j++)
  36. for(int i=2;i<=n;i++)
  37. {
  38. parent[i][j]=parent[parent[i][j-1]][j-1];
  39. if(parent[i][j]>=1)
  40. dist[i][j]=dist[parent[i][j-1]][j-1]+dist[i][j-1];
  41. }
  42. for(int i=1;i<=n;i++)
  43. cout<<parent[i][0]<<" "<<parent[i][1]<<" "<<parent[i][2]<<endl;
  44.  
  45.  
  46. }
  47.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
4
1 4
1 3
2 4
compilation info
prog.cpp: In function ‘void dfs(long long int, long long int)’:
prog.cpp:16:38: error: request for member ‘second’ in ‘a[i].std::vector<_Tp, _Alloc>::operator[]<long long int, std::allocator<long long int> >(((std::vector<long long int>::size_type)j))’, which is of non-class type ‘__gnu_cxx::__alloc_traits<std::allocator<long long int> >::value_type {aka long long int}’
             dist[a[i][j]][0]=a[i][j].second;
                                      ^~~~~~
stdout
Standard output is empty