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. .gitignore排除(不忽略)二级以上目录下的文件或目录

    在.gitignore中,结合使用/*和!filename的语法,可以达到除特定文件或目录外全部忽略的目的.但当希望不忽略的文件或目录在二级或多级目录下时,如果这样写 /* !/sub/subsub/ ...

  2. Mysql性能优化:为什么要用覆盖索引?

    导读 相信读者看过很多MYSQL索引优化的文章,其中有很多优化的方法,比如最佳左前缀,覆盖索引等方法,但是你真正理解为什么要使用最佳左前缀,为什么使用覆盖索引会提升查询的效率吗? 本篇文章将从MYSQ ...

  3. Java——Collection集合

    ##Collection集合 1.Collection集合是单列集合 2.Collection是所有单列集合最顶层的接口,定义了所有单列集合的共性方法 任意的单列集合都可以使用Collection接口 ...

  4. 图-连通分量-DFS-并查集-695. 岛屿的最大面积

    2020-03-15 16:41:45 问题描述: 给定一个包含了一些 0 和 1的非空二维数组 grid , 一个 岛屿 是由四个方向 (水平或垂直) 的 1 (代表土地) 构成的组合.你可以假设二 ...

  5. 牛客网剑指offer【Python实现】——part1

    斐波那契数列 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0,n<=39). 循环实现,时间复杂度n def Fibonacci(self, ...

  6. OpenCV-Python 图像上的算术运算 | 十一

    目标 学习图像的几种算术运算,例如加法,减法,按位运算等. 您将学习以下功能:cv.add,cv.addWeighted等. 图像加法 您可以通过OpenCV函数cv.add()或仅通过numpy操作 ...

  7. Python python对象 enumerate

    """ enumerate(iterable[, start]) -> iterator for index, value of iterable Return a ...

  8. 本地不安装Oracle时,PLSQL的配置

    这篇我在csdn上写过的,文章地址:https://blog.csdn.net/weixin_40404606/article/details/101940542

  9. c语言提取浮点型数据的整数部分与小数部分几种方法

    一 前记 最近涉及到把各种传感器的数据通过wifi和bt传输出去,这就涉及到了浮点传输的问题,为了方便传输,笔者的做法一般是把小数和整数部分分开,分别传输,这就比较简单明晰了. 二 方法论 其实,把浮 ...

  10. elasticsearch在linux上的安装,Centos7.X elasticsearch 7.6.2

    本文环境:Elasticsearch7.6.2目前最先版本   centos7.X     JDK1.8 elasticsearch介绍 官网:https://www.elastic.co/cn/pr ...