X - Ehab and Path-etic MEXs CodeForces - 1325C
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的更多相关文章
- D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)
http://codeforces.com/contest/862/problem/D 交互题 fflush(stdout) 调试: 先行给出结果,函数代替输入 #include <cstdio ...
- 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 ...
- Codeforces Round #396.D
D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input ...
- Codeforces 766D. Mahmoud and a Dictionary 并查集 二元敌对关系 点拆分
D. Mahmoud and a Dictionary time limit per test:4 seconds memory limit per test:256 megabytes input: ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- django 之 Ajax and so on
MTV与MVC(了解)
- 洛谷P1003 铺地毯 模拟
这一题就是一个很普通的模拟,每次输入的时候存储四个角的值 把四个角的横纵坐标存储在一排.然后在倒序遍历一遍,查找的时候就看所要查找的坐标在不在这个范围内,如果找到了就标记一下再输出,如果没有找到就输出 ...
- 为什么信息熵要定义成-Σp*log(p)?
作者:西贝链接:https://www.zhihu.com/question/30828247/answer/64816509来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出 ...
- NLPer,你知道最近很火的自然语言处理库么?
介绍 "NLP's ImageNet moment has arrived." 想象一下我们有能力构建支持谷歌翻译的自然语言处理(NLP)模型,并且在Python中仅需几行代码来完 ...
- 一夜搞懂 | JVM 字节码执行引擎
前言 本文已经收录到我的 Github 个人博客,欢迎大佬们光临寒舍: 我的 GIthub 博客 学习导图 一.为什么要学习字节码执行引擎? 代码编译的结果从本地机器码转变为字节码,是存储格式发展的一 ...
- 【3D】PoseCNN姿态检测网络复现过程记录
最近在研究室内6D姿态检测相关问题,计划在PoseCNN网络基础上进行改进实现.但是在第一步的复现过程中踩了无数的坑,最终成功运行了demo,但目前数据集train还是遇到了一些问题.有问题欢迎一起交 ...
- 快,学会 shell
本文分成入门篇和基础篇.基础篇包括变量.字符串处理.数学运算三部分.基础篇包括流控制.函数和函数库三部分.主要是基于例子进行讲解,其中有 4 个复杂一点的脚本,看懂了也就入门了. 我们先来聊一聊 sh ...
- Javascript-什么是递归?
递归? 程序调用自身的编程技巧就称之为递归(recursion),就是再运行的过程中调用自己,本质上就是循环. 构成递归的条件有: Ⅰ.不能无限制的调用本身,必须有一个出口,化为简单的状况处理(非递归 ...
- Codeforces Round #565 (Div. 3)--D. Recover it!--思维+欧拉筛
D. Recover it! Authors guessed an array aa consisting of nn integers; each integer is not less than ...
- 人工智能新手入门学习路线和学习资源合集(含AI综述/python/机器学习/深度学习/tensorflow)
[说在前面]本人博客新手一枚,象牙塔的老白,职业场的小白.以下内容仅为个人见解,欢迎批评指正,不喜勿喷![握手][握手] 1. 分享个人对于人工智能领域的算法综述:如果你想开始学习算法,不妨先了解人工 ...