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--;}}
} 

CodeForces - 1325C Ehab and Path-etic MEXs相关推荐

  1. [codeforces 1325C] Ehab and Path-etic MEXs 绕不开的叶节点+特判

    Codeforces Round #628 (Div. 2)   比赛人数9400 [codeforces 1325C]  Ehab and Path-etic MEXs   绕不开的叶节点+特判 总 ...

  2. Codeforces 1325C. Ehab and Path-etic MEXs(构造)

    Description You are given a tree consisting of n nodes. You want to write some labels on the tree's ...

  3. [Codeforces Round #628]1325C - Ehab and Path-etic MEXs[思维][图]

    1325C - Ehab and Path-etic MEXs[思维][图] time limit per test memory limit per test input output 1 seco ...

  4. Codeforces 1088E Ehab and a component choosing problem(树形DP)

    Codeforces 1088E Ehab and a component choosing problem(树形DP) 题意 给一棵树,要求从中选一些联通分量,使得平均联通分量重量总和最大.如果有多 ...

  5. Ehab and Path-etic MEXs CodeForces - 1325C(思维+贪心)

    You are given a tree consisting of n nodes. You want to write some labels on the tree's edges such t ...

  6. codeforces C. Ehab and Path-etic MEXs

    题目 题意: 你有nnn个点,n−1n-1n−1条边,现在需要将max(MEX(u,v))max(MEX(u, v))max(MEX(u,v))越小越好,MEX(u,v)MEX(u, v)MEX(u, ...

  7. Codeforces C. Ehab and Path-etic MEXs (树 / 构造 / MEX)

    传送门 题意: 给定一个 n 个节点 n−1 条边的树,要求给边重新标注边权,分别为 0,1,2-n-20,1,2-n−2 .然后使得树上任意两点 u,v的 MEX(u,v) 的最大值最小. MEX( ...

  8. CodeForces - 1174D Ehab and the Expected XOR Problem(构造+思维+位运算)

    题目链接:点击查看 题目大意:给出一个 n,再给出一个 x,要求构造一个数列,满足该数列的所有子串的异或和都不等于 0 且都不等于 x,在满足上面的条件下尽可能长 题目分析:因为这个题目最终的目标是需 ...

  9. CodeForces - 1364C Ehab and Prefix MEX(贪心+构造)

    题目链接:点击查看 题目大意:给出一个数组 a ,要求构造一个数组 b ,使得 a[ i ] = MEX{ b[ 1 ] , b[ 2 ] , ... b[ i - 1 ] , b[ i ] },a[ ...

最新文章

  1. 关于Mysql5.6 Failed to open file error2的记录
  2. MySQL学习笔记01【数据库概念、MySQL安装与使用】
  3. 面试题57 - II. 和为s的连续正数序列 golang
  4. VueCli3 项目结构和具体作用
  5. 设置linux文件系统密码,busybox 文件系统设置 登陆 login 密码 password shadow
  6. 滑动窗口解决最小子串问题 leetcode3. Longest Substring Without Repeating Characters
  7. Netty实现原理分析
  8. 二叉链表和职工管理系统结合_职工信息管理系统单链表实现C语言源程序
  9. 二、ArcGIS中shp裁剪dem
  10. 【RocketMQ】Send [1] times, still failed以及No route info of this topic问题排查思路总结
  11. 教你怎么免费升级宝塔企业版和专业版
  12. Docker核心技术(一):镜像与容器
  13. python——列表定义及方法
  14. PHP 生成 ppt,php生成导出Word、Excel、PowerPoint插件
  15. 【愚公系列】2022年03月 FTP及Telnet弱口令渗透测试之字典生成器
  16. python与工程造价的联系_工程造价和工程预算是一个概念吗?
  17. 增广拉格朗日乘子法、ADMM
  18. 记录修复Ubuntu20.04开机后桌面卡住只有鼠标能动
  19. 西北师大计算机复试英语,西北师范英语语言文学英美文学复试
  20. mysql 增加主键列_MySQL添加列、删除列,创建主键等常用操作总结

热门文章

  1. Win10安装MySQL8压缩包版
  2. [转]第三届标致汽车设计国际邀请赛部分获奖作品展示
  3. Redis——Windows安装
  4. #论文笔记#【MRM-Lasso:A sparse Multiview Feature Selection Method Via Low-Rank Analysis】论文笔记
  5. 做毕设途中遇到了问题,求大神指教。
  6. 有关python的比赛_用 Python 写一个 Kaggle 比赛排行榜的爬虫
  7. web直播、即时聊天流程图。第三方平台
  8. AppWidget(桌面小部件)
  9. 手机网站一键秒变App?详细教程来了
  10. Linux服务 httpd