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 ...
随机推荐
- 动态规划-划分数组的最大和 Split Array Largest Sum
2019-10-14 22:13:18 问题描述: 问题求解: 解法一:动态规划 这种数组划分的题目基本都可以使用dp来解决,核心的思路就是先维护低的划分,再在中间找分割点加入新的划分. public ...
- 条件随机场 CRF
2019-09-29 15:38:26 问题描述:请解释一下NER任务中CRF层的作用. 问题求解: 在做NER任务的时候,神经网络学习到了文本间的信息,而CRF学习到了Tag间的信息. 加入CRF与 ...
- Redis总结--【持续更新】
# 什么是Redis? Redis 是完全开源免费的,是一个高性能的key-value内存数据库,读的速度是110000次/s,写的速度是81000次/s 它有以下三个特点: Redis不 ...
- 模型压缩一半,精度几乎无损,TensorFlow推出半精度浮点量化工具包,还有在线Demo...
近日,TensorFlow模型优化工具包又添一员大将,训练后的半精度浮点量化(float16 quantization)工具. 有了它,就能在几乎不损失模型精度的情况下,将模型压缩至一半大小,还能改善 ...
- 有个原则就是实体类还是controller入参都应该是 包装类型
问题说明 我在使用JPA作为项目的ORM框架的时候,在分页查询中,不管咋样使用查询不出来数据,然后发现Hibernate构建的查询SQL中,在where子句中带上了createTime=0这个条件.这 ...
- coding++:Spring Boot 全局事务解释及使用(二)
什么是全局事务: Spring Boot(Spring) 事务是通过 aop(aop相关术语:通知(Advice).连接点(Joinpoint).切入点(Pointcut).切面(Aspect).目标 ...
- Springcloud config + zuul 搭建动态网关
1,实现的效果,就是zuul 网关的配置路由实现负载均衡,zuul 的配置文件放在springcloud config 上 2,需要的服务如下: 3,其实就是配置下springcloud-zuul 的 ...
- python实现杨辉三角形
代码实现: # python实现杨辉三角形 def yanghui(): # 定义第一行列表为[1] line = [1] while True: # yield的作用:把一个函数变成生成器,同时返回 ...
- rem样板
window.onload=window.onresize=function(){ var rem=document.documentElement.clientWidth*20/320; docum ...
- PTA 7-42 整型关键字的散列映射(手写哈希表的线性探测法)
本题考点: 整型哈希表的线性探测法 给定一系列整型关键字和素数P,用除留余数法定义的散列函数将关键字映射到长度为P的散列表中.用线性探测法解决冲突. 输入格式: 输入第一行首先给出两个正整数N(≤10 ...