CodeForces - 1325C Ehab and Path-etic MEXs

You are given a tree consisting of nn nodes. You want to write some labels on the tree's edges such that the following conditions hold:

  • Every label is an integer between 00 and n−2n−2 inclusive.
  • All the written labels are distinct.
  • The largest value among MEX(u,v)MEX(u,v) over all pairs of nodes (u,v)(u,v) is as small as possible.

Here, MEX(u,v)MEX(u,v) denotes the smallest non-negative integer that isn't written on any edge on the unique simple path from node uu to node vv.

Input

The first line contains the integer nn (2≤n≤1052≤n≤105) — the number of nodes in the tree.

Each of the next n−1n−1 lines contains two space-separated integers uu and vv (1≤u,v≤n1≤u,v≤n) that mean there's an edge between nodes uu and vv. It's guaranteed that the given graph is a tree.

Output

Output n−1n−1 integers. The ithith of them will be the number written on the ithith edge (in the input order).

Examples

Input

3
1 2
1 3

Output

0
1

Input

6
1 2
1 3
2 4
2 5
5 6

Output

0
3
2
4
1

Note

The tree from the second sample:

Sponsor

贪心就行 只要是叶节点就从0往后递增

不是根节点就从n-2往前递减

#include<bits/stdc++.h>
const int maxn = 1e5 + 5;
int degree[maxn];
int a[maxn];
int b[maxn];
using namespace std;
int main(){
	int n;
	cin >> n;
	for(int i = 1; i < n; i++){
		cin >> a[i] >> b[i];
		degree[a[i]]++;
		degree[b[i]]++;
	}
	int cnt = 0;
	int cnt2 = n - 2;
	for(int i = 1; i < n; i++){
		if(degree[a[i]] == 1 || degree[b[i]] == 1){
			cout << cnt << endl;
			cnt++;
		}
		else{
			cout << cnt2 << endl;
			cnt2--;
		}
	}
} 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值