Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- vector<int> v[100005];
- int ans[100005];
- int main()
- {
- int n;
- scanf("%d",&n);
- for (int i=1;i<n;i++)
- {
- int a,b;
- scanf("%d%d",&a,&b);
- v[a].push_back(i);
- v[b].push_back(i);
- ans[i]=-1;
- }
- pair<int,int> mx(0,0);
- for (int i=1;i<=n;i++)
- mx=max(mx,make_pair((int)v[i].size(),i));
- int cur=0;
- for (int i:v[mx.second])
- ans[i]=cur++;
- for (int i=1;i<n;i++)
- {
- if (ans[i]==-1)
- ans[i]=cur++;
- printf("%d\n",ans[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement