Advertisement
Guest User

Untitled

a guest
Mar 14th, 2020
9,877
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. vector<int> v[100005];
  4. int ans[100005];
  5. int main()
  6. {
  7.     int n;
  8.     scanf("%d",&n);
  9.     for (int i=1;i<n;i++)
  10.     {
  11.         int a,b;
  12.         scanf("%d%d",&a,&b);
  13.         v[a].push_back(i);
  14.         v[b].push_back(i);
  15.         ans[i]=-1;
  16.     }
  17.     pair<int,int> mx(0,0);
  18.     for (int i=1;i<=n;i++)
  19.     mx=max(mx,make_pair((int)v[i].size(),i));
  20.     int cur=0;
  21.     for (int i:v[mx.second])
  22.     ans[i]=cur++;
  23.     for (int i=1;i<n;i++)
  24.     {
  25.         if (ans[i]==-1)
  26.         ans[i]=cur++;
  27.         printf("%d\n",ans[i]);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement