codeforce C. Ehab and Path-etic MEXs
题目大意:有一颗n个结点的树 ,现在让你分配每条边的权重,使得任意两个点之间的所有边的MEX值尽可能的小。
题解:寻找两个隶属于同一父亲的叶子节点,将两条边分别赋值为0和1,那么所有路径上的MEX值最大为1。显然由于0的存在,MEX不可能为0,所以1就是最小值。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
vector<int>g[maxn];
struct node {int u, v;
}e[maxn];
int main()
{int n, k;cin >> n;int x, y;for (int i = 1; i <= n - 1; i++){cin >> x >> y;g[x].push_back(y);g[y].push_back(x);e[i].u = x;e[i].v = y;}int mx = n - 2, mi = 0;for (int i = 1; i < n; i++){if (g[e[i].u].size() == 1 || g[e[i].v].size() == 1){cout << mi++ << endl;}else cout << mx-- << endl;}}
codeforce C. Ehab and Path-etic MEXs相关推荐
- 【字源大挪移—读书笔记】 第一部分:字首
[1] 字首:[1.1]表示[否定]的字首.[1.2]表示[方位]的字首.[1.3]表示[程度]的字首.[1.4]表示[状态.现象]的字首.[1.5]表示[数字]的字首 [1.1] 表示[否定]的字首 ...
- Codeforces round #628 C.Ehab and Path-etic MEXs
Codeforces round #628 C.Ehab and Path-etic MEXs You are given a tree consisting of n nodes. You want ...
- [Codeforces Round #628]1325C - Ehab and Path-etic MEXs[思维][图]
1325C - Ehab and Path-etic MEXs[思维][图] time limit per test memory limit per test input output 1 seco ...
- Codeforces Round #649 (Div. 2)C. Ehab and Prefix MEXs[排列的构造]
C. Ehab and Prefix MEXs 题目大意: 解题思路:题目说保证a数组是非递减的,那么如果某位置a[i]!=a[i−1]a[i]!=a[i-1]a[i]!=a[i−1]那么这个位置ii ...
- Codeforces Round #628 (Div. 2)C - Ehab and Path-etic MEXs
C - Ehab and Path-etic MEXs 题目链接 简要描述: 从一个点到另一个点出发,所经过的边组成一个集合, 这些集合中所不包含的最小自然数为mex(u,v),要求使所有的mex(u ...
- Codeforces Round #628 (Div. 2) C. Ehab and Path-etic MEXs
C. Ehab and Path-etic MEXs 题目链接-C. Ehab and Path-etic MEXs Note The tree from the second sample: 题目大 ...
- CF628 C.C. Ehab and Path-etic MEXs(思维+拓扑排序)
CF628 C.C. Ehab and Path-etic MEXs(思维+拓扑排序) 题目链接 题意:没咋看懂,它的题解是度数最高的分配后其他的随便分配. 我做的是,从子节点往上面,依次加,拓扑排序 ...
- [codeforces 1325C] Ehab and Path-etic MEXs 绕不开的叶节点+特判
Codeforces Round #628 (Div. 2) 比赛人数9400 [codeforces 1325C] Ehab and Path-etic MEXs 绕不开的叶节点+特判 总 ...
- Ehab and Path-etic MEXs CodeForces - 1325C(思维+贪心)
You are given a tree consisting of n nodes. You want to write some labels on the tree's edges such t ...
最新文章
- [转载]商业智能的三个层次
- SQL server 中SQL语句实战操作
- java gsp_GSP序列模式分析算法
- Go连接及操作MySQL
- 系统ghost后变成一个盘了别的分区的文件怎么找回
- 客户端 获取服务器性能,客户端数量 服务器性能
- 方形物体绕中心旋转的扭力_三维旋转
- Spring Boot:快速启动MVC
- 云计算的思想领袖:与Tier3的创始人和首席技术官Jared Wray的谈话
- C 设计语言编译生成的是中间语言IL,一、源代码-面向CLR的编译器-托管模块-(元数据IL代码)...
- 《A Point Set Generation Network for 3D Object Reconstruction from a Single Image》论文笔记_2D图像生成3D点云
- 线性移位寄存器序列(m序列)之MATLAB实现
- android 谷歌地图离线访问,谷歌升级Android版地图应用 支持离线使用
- w ndoWs8pE模式下载,windows pe官方版下载_windows pe v8.2 - Win7旗舰版
- mtouch 3d gis,m3dgis,mtgis,mgis 多点触摸三维电子沙盘可视化交互系统教程第17课
- Python下载和安装图文教程[超详细]
- 全国计算机英语四六级准考证打印,周六开考!2020年11月四六级口语考试准考证打印通知!...
- oracle direct-load,sqlldr direct方式导致索引失效实测
- 深入理解地址翻译 CSAPP
- Pytorch3d中的倒角损失函数Chamfer Distance Loss的用法(pytorch3d.loss.chamfer_distance)