MMP,差一点就做对了。

题目大意:给你一个树,对这个树的边进行编号,编号要求从0到n-1,不可重复,要求MEX(U,V)尽可能的小,

MEX(x,y)的定义:从x到y的简单路径上,没有出现的最小编号。

题解:

只要让0,1,2这三个号不在同一条路径上就行。

如果说是一条没有分支的树,那么无论怎么编号,MEX等于n-1。对于有分支的树,只要让他的叶子节点所连的边从小到大编号就行。。注意无向图求叶子节点的方法。。。。

度数那一步弄错了。。。

注意对小于2的树特判一下,就一条边,也就是0喽。

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
int arr[N];
int inv[N];
int mark[N];
struct stu {
int x,y;
}pre[N];
int main(){
int n;
cin>>n; for(int i=;i<n;i++){
int x,y;
cin>>x>>y;
pre[i]={x,y};
inv[x]++;
inv[y]++;
}
if(n==) {
cout<<<<endl;
return ;
}
int pos=;
for(int i=;i<=n;i++){
if(inv[i]==) {
mark[i]=pos++;
}
}
for(int i=;i<n;i++){
if(inv[pre[i].x]==) cout<<mark[pre[i].x]<<endl;
else if(inv[pre[i].y]==) cout<<mark[pre[i].y]<<endl;
else cout<<pos++<<endl;
}
return ;
}

X - Ehab and Path-etic MEXs CodeForces - 1325C的更多相关文章

  1. D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)

    http://codeforces.com/contest/862/problem/D 交互题 fflush(stdout) 调试: 先行给出结果,函数代替输入 #include <cstdio ...

  2. Codeforces Round #396 (Div. 2) A,B,C,D,E

    A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...

  3. Codeforces Round #396.D

    D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input ...

  4. Codeforces 766D. Mahmoud and a Dictionary 并查集 二元敌对关系 点拆分

    D. Mahmoud and a Dictionary time limit per test:4 seconds memory limit per test:256 megabytes input: ...

  5. Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary 并查集

    D. Mahmoud and a Dictionary 题目连接: http://codeforces.com/contest/766/problem/D Description Mahmoud wa ...

  6. Codeforces 766D Mahmoud and a Dictionary 2017-02-21 14:03 107人阅读 评论(0) 收藏

    D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input ...

  7. CF 959 E. Mahmoud and Ehab and the xor-MST

    E. Mahmoud and Ehab and the xor-MST https://codeforces.com/contest/959/problem/E 分析: 每个点x应该和x ^ lowb ...

  8. Codeforces Round #396 (Div. 2) A B C D 水 trick dp 并查集

    A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...

  9. Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary

    地址:http://codeforces.com/contest/766/problem/D 题目: D. Mahmoud and a Dictionary time limit per test 4 ...

随机推荐

  1. effective-java学习笔记---使用标记接口定义类型40

    标记接口(marker interface),不包含方法声明,只是指定(或“标记”)一个类实现了具有某些属性的接口. 例如,考虑 Serializable 接口.通过实现这个接口,一个类表明它的实例可 ...

  2. MNIST数据集介绍

    大多数示例使用手写数字的MNIST数据集[^1].该数据集包含60,000个用于训练的示例和10,000个用于测试的示例.这些数字已经过尺寸标准化并位于图像中心,图像是固定大小(28x28像素),其值 ...

  3. 蓝桥杯 K好数(Java)

    越来越觉得自己菜,一道简单的动态规划写不出来,题解也是看了很多份才看懂了,所以尽量以图表的方式写了题解,希望我的题解能帮到其他人吧.(;´Д`) 首先是题目: 输入描述: 输入包含两个正整数,K和L. ...

  4. CI / CD /CD 持续集成 持续交付 持续部署

    CI / CD /CD 持续集成 持续交付 持续部署 CI CD 是啥?干了啥? CI continuous integration 持续集成 CD continuous delivery 持续交付 ...

  5. 模块 subprocess 交互shell

    subprocess 交互shell 执行shell命令, 与操作系统交互 三种执行命令的方法 subprocess.run(*popenargs, input=None, timeout=None, ...

  6. turtle实例

    1.彩虹 (1) from turtle import * def HSB2RGB(hues): hues = hues * 3.59 #100转成359范围 rgb=[0.0,0.0,0.0] i ...

  7. HashCode()与equals()深入理解

    1.hashCode()和equals()方法都是Object类提供的方法, hashCode()返回该对象的哈希码值,该值通常是一个由该对象的内部地址转换而来的int型整数, Object的equa ...

  8. RocketMQ调研

    一.发展历程 早期淘宝内部有两套消息中间件系统:Notify和Napoli. 先有的Notify(至今12历史),后来因有序场景需求,且恰好当时Kafka开源(2011年),所以参照Kafka的设计理 ...

  9. C - 啥~ 渣渣也想找玩数字 HDU - 2141(有序序列枚举 + 二分优化查找)

    题目描述 可爱的演演又来了,这次他想问渣渣一题... 如果给你三个数列 A[],B[],C[],请问对于给定的数字 X,能否从这三个数列中各选一个,使得A[i]+B[j]+C[k]=X? 输入 多组数 ...

  10. 接口测试彻底弄懂Session、Cookie、Token的区别及联系hold住面试官--hold住了开3万,hold不住开3K!

    一.前言:接口测试之伤:cookie,session,token本是一家! cookie,session,token的区别早就已经成为测试同行的心病,各大论坛,各大博客,各大视频网站无不充斥着各种疑问 ...