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. django 之 Ajax and so on

    MTV与MVC(了解)

  2. linggle使用技巧

    Linggle 搜索引擎是一个可用于英语写作的语法.句子工具,可帮助学习者分析更准确的英文写作建议,能够根据词性来推测短句和句子,可精准的分享出完整英文句子如何撰写. Linggle 是台湾学术团队研 ...

  3. 干货 | 近期热点机器学习git项目

    No1:PyTorchImplementation of DeepMind's BigGAN(https://github.com/huggingface/pytorch-pretrained-Big ...

  4. AC自动机(初步学习)

    一开始讲AC自动机就是在字典树上做一个KMP,吓得我感觉好难,不过了解了以后,感觉也就是有点难度,不吓人. 它只是在字典树上用了KMP的思想 典型问题:给n个模式串和一个文本串,问有多少个模式串在文本 ...

  5. Springboot + Freemarker(一)

    Maven pom文件配置 <parent> <groupId>org.springframework.boot</groupId> <artifactId& ...

  6. 浅谈服务架构“五脏六腑”之Spring Cloud

    本文将从 Spring Cloud 出发,分两小节讲述微服务框架的「五脏六腑」: 第一小节「服务架构」旨在说明的包括两点,一服务架构是什么及其必要性:二是服务架构的基本组成.为什么第一节写服务架构而不 ...

  7. Mob 之 短信验证集成 SMSSDK

    开相关发中总会遇到短信验证这些操作,这周没有来得及写新的东西,借此分享一篇以前学习短信验证的笔记,本文使用的是 Mob 提供的 SMSSDK . 下载 SMSSDK 官网下载地址:SMSSDK 集成 ...

  8. 关于dll劫持我的奇思妙想(一)

    0x00  前言 前段时间在研究着windows底层的一些东西,发现这个dll劫持一直没有做过,根据倾旋师傅的视频和文章做了一系列的研究,然后就突发来了兴致研究一些dll劫持提权. 0x01   了解 ...

  9. 2783: 【基础】小 X 玩游戏(game)

    2783: [基础]小 X 玩游戏(game) 时间限制: 1 Sec 内存限制: 64 MB 提交: 752 解决: 294 [提交] [状态] [讨论版] [命题人:ghost79] 题目描述 听 ...

  10. python爬虫之requests的高级使用

    1.requests能上传文件 # 导入requests模块 import requests # 定义一个dict files = {'file': open('D:/360Downloads/1.t ...