链接:https://codeforces.ml/contest/1325/problem/C

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 uuand 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

Copy

3
1 2
1 3

output

Copy

0
1

input

Copy

6
1 2
1 3
2 4
2 5
5 6

output

Copy

0
3
2
4
1

Note

The tree from the second sample:

正在上传…重新上传取消

主要难在读题。。。

#include<bits/stdc++.h>
using namespace std;
long long n,t,k,s,u[100005],v[100005];
map<long long,long long>m;
long long a[1000001];
int main()
{cin>>n;int k=0;for(int i=1;i<=n-1;i++){cin>>u[i]>>v[i];m[u[i]]++;m[v[i]]++;a[i]=-1;}int j=n-2;for(int i=1;i<=n-1;i++){if(m[u[i]]==1||m[v[i]]==1)continue;else{a[i]=j;j--;}}for(int i=1;i<=n-1;i++){if(a[i]==-1){a[i]=j;j--;}}for(int i=1;i<=n-1;i++)cout<<a[i]<<endl;
}

C. Ehab and Path-etic MEXs相关推荐

  1. 【字源大挪移—读书笔记】 第一部分:字首

    [1] 字首:[1.1]表示[否定]的字首.[1.2]表示[方位]的字首.[1.3]表示[程度]的字首.[1.4]表示[状态.现象]的字首.[1.5]表示[数字]的字首 [1.1] 表示[否定]的字首 ...

  2. Codeforces round #628 C.Ehab and Path-etic MEXs

    Codeforces round #628 C.Ehab and Path-etic MEXs You are given a tree consisting of n nodes. You want ...

  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 Round #649 (Div. 2)C. Ehab and Prefix MEXs[排列的构造]

    C. Ehab and Prefix MEXs 题目大意: 解题思路:题目说保证a数组是非递减的,那么如果某位置a[i]!=a[i−1]a[i]!=a[i-1]a[i]!=a[i−1]那么这个位置ii ...

  5. Codeforces Round #628 (Div. 2)C - Ehab and Path-etic MEXs

    C - Ehab and Path-etic MEXs 题目链接 简要描述: 从一个点到另一个点出发,所经过的边组成一个集合, 这些集合中所不包含的最小自然数为mex(u,v),要求使所有的mex(u ...

  6. Codeforces Round #628 (Div. 2) C. Ehab and Path-etic MEXs

    C. Ehab and Path-etic MEXs 题目链接-C. Ehab and Path-etic MEXs Note The tree from the second sample: 题目大 ...

  7. CF628 C.C. Ehab and Path-etic MEXs(思维+拓扑排序)

    CF628 C.C. Ehab and Path-etic MEXs(思维+拓扑排序) 题目链接 题意:没咋看懂,它的题解是度数最高的分配后其他的随便分配. 我做的是,从子节点往上面,依次加,拓扑排序 ...

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

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

  9. 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 ...

最新文章

  1. 大模型技术实践路线图出炉,唐杰牵头,近百位智源、清华、北大、MILA等顶尖研究者联合推出...
  2. C# 3.0 New Language Features (Part 1)
  3. Linux--Sys_Read系统调用过程分析
  4. 高级进阶:Azure DevOps搞定.NET Core编译版本号自增
  5. 方法重载与重写,返回类型
  6. JUnit5 @BeforeAll注解示例
  7. 谈谈JavaScript中的function constructor和new关键字
  8. 生成jacoco报告_测开技能之如何利用ant jacoco 合并覆盖率报告
  9. 在万彩手影大师上怎么制作微课_手势动画制作|万彩手影大师心得与教程
  10. live2d_Live2D 性能优化
  11. 关于同时安装Keil4MDK与C51问题
  12. 山东科技大学计算机研究生学院官网,山东科技大学-计算机科学与工程学院
  13. mysql数据库加密存储过程_数据库系统(六)---MySQL语句及存储过程
  14. CSS滤镜实现鼠标悬停图片变黑白(灰色)
  15. flink 空闲窗口-withIdleness
  16. linux 挂载4t移动硬盘,Linux挂载移动硬盘
  17. hevc sps 序列参数集
  18. MODIS冰雪数据批量下载
  19. 【ArcMap学习系列】符号编辑与制作(国界、省界、区县界等线状符号制作方法)
  20. linux xia shan chu wenjian

热门文章

  1. RBM-MHC: A Semi-Supervised Machine-LearningMethod for Sample-Specific Prediction of AntigenPresent
  2. vue 使用gtm代码代替ga代码作谷歌分析
  3. C#软件winform程序安装包制作
  4. phpcms选择文件无法加载插件怎么办_浏览器显示无法加载插件怎么办
  5. swift Dictionary 字典
  6. 表示自己从头开始的句子_形容从头开始的句子
  7. pyautocad相关操作案例
  8. 空调器制冷系统故障-蒸发器反面脏堵
  9. 智能晾衣杆_晾衣绳社交书签–仅CSS的社交书签教程
  10. 百度统计中的索引量和site:命令的百度收录量不一致的原因