Codeforces Round #628 (Div. 2) C. Ehab and Path-etic MEXs(树,思维题)
题意:
给有 n 个点的树的 n-1 条边从 0 到 n-2 编号,使得任意两点路径中未出现的最小数最小的方案。
思路:
先给所有度为 1 的点所在边编号,之后其他点可以随意编排。
#include <bits/stdc++.h>
using namespace std; const int M=110000; vector<vector<int>> e(M);
vector<pair<int,int>> a; map<pair<int,int>,int> m; int main()
{
int n;cin>>n;
for(int i=0;i<n-1;i++){
int u,v;cin>>u>>v;
e[u].push_back(v);
e[v].push_back(u);
a.push_back(make_pair(u,v));
} int num=1;
for(int i=1;i<=n;i++){
if(e[i].size()==1){
for(int j:e[i]){
pair<int,int> p1=make_pair(i,j);
pair<int,int> p2=make_pair(j,i);
if(!m[p1])
m[p1]=m[p2]=num++;
}
}
} for(int i=1;i<=n;i++){
if(e[i].size()!=1){
for(int j:e[i]){
pair<int,int> p1=make_pair(i,j);
pair<int,int> p2=make_pair(j,i);
if(!m[p1])
m[p1]=m[p2]=num++;
}
}
} for(auto i:a){
cout<<m[i]-1<<endl;
} return 0;
}
Codeforces Round #628 (Div. 2) C. Ehab and Path-etic MEXs(树,思维题)的更多相关文章
- Codeforces Round #628 (Div. 2) D. Ehab the Xorcist(异或,思维题)
题意: 寻找异或后值为 u,相加后和为 v 的最短数组. 思路: 异或得 u ,则 v 至少应大于等于 u ,且多出来的部分可以等分为两份相消. 即初始数组为 u , (v-u)/2 , (v-u)/ ...
- Codeforces Round #628 (Div. 2) A. EhAb AnD gCd(LCM & GCD)
题意: GCD(a,b) + LCM(a,b) = n,已知 n ,求 a,b. 思路: 设 gcd(a, b) = k, a = xk, b = yk , k + ab / k = n xy = n ...
- Codeforces Round #554 (Div. 2) B. Neko Performs Cat Furrier Transform(思维题+log2求解二进制位数的小技巧)
传送门 题意: 给出一个数x,有两个操作: ①:x ^= 2k-1; ②:x++; 每次操作都是从①开始,紧接着是② ①②操作循环进行,问经过多少步操作后,x可以变为2p-1的格式? 最多操作40次, ...
- Codeforces Round #539 (Div. 2) - D. Sasha and One More Name(思维)
Problem Codeforces Round #539 (Div. 2) - D. Sasha and One More Name Time Limit: 1000 mSec Problem ...
- Codeforces Round #267 (Div. 2) C. George and Job(DP)补题
Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...
- Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题
Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...
- Codeforces Round #525 (Div. 2) F. Ehab and a weird weight formula
F. Ehab and a weird weight formula 题目链接:https://codeforces.com/contest/1088/problem/F 题意: 给出一颗点有权值的树 ...
- Codeforces Round #525 (Div. 2)E. Ehab and a component choosing problem
E. Ehab and a component choosing problem 题目链接:https://codeforces.com/contest/1088/problem/E 题意: 给出一个 ...
- Codeforces Round #525 (Div. 2)D. Ehab and another another xor problem
D. Ehab and another another xor problem 题目链接:https://codeforces.com/contest/1088/problem/D Descripti ...
随机推荐
- fastjson复现项目代码
详情请见:https://www.cnblogs.com/yunmuq/p/14268028.html 以下是代码 // FastjsonDemo.java package test; import ...
- WebRTC ICE 状态与提名处理
大家都知道奥斯卡有提名,其实在 WebRTC 的 ICE 中也有提名,有常规的提名,也有激进的提名,而且提名的候选人不一定是最优秀的候选人喔,本文就带你一探其中玄妙.文章内容主要描述 RFC 5245 ...
- 【MyBatis】自定义 MyBatis
自定义 MyBatis 文章源码 执行查询信息的分析 我们知道,MyBatis 在使用代理 DAO 的方式实现增删改查时只做两件事: 创建代理对象 在代理对象中调用 selectList() 配置信息 ...
- Spring MVC 接收 LocalDate、LocalTime 和 LocalDateTime Java 8 时间类型参数
使用 Spring MVC 时,很多业务场景下 Controller 需要接收日期时间参数.一个简单的做法是使用 String 接收日期时间字符串(例如:2020-01-29),然后在代码中将其转换成 ...
- LeetCode671. 二叉树中第二小的节点
题目 纯暴力 1 class Solution { 2 public: 3 vector<int>ans; 4 int findSecondMinimumValue(TreeNode* r ...
- XSS - Labs 靶场笔记(上)
上周在网上看到的一个XSS平台,刷一波<doge Less - 1: 1.进入主界面,由图二可知是GET请求,提交name=test,回显在页面 2.查看源代码可知 没有做任何过滤,显然存在反射 ...
- 微软官网下载win10离线介质
1.打开google浏览器 2.搜索win10官网下载或者直接输入网址https://www.microsoft.com/zh-cn/software-download/windows10 3.按F1 ...
- Ice系列--强大如我IceGrid
前言 IceGrid是一个提供服务定位和服务激活的组件,但它的功能远不止于此.从它的命名可以看出它的设计理念-网格计算(grid computing).网格计算被定义为由一系列关联的廉价计算机组成的计 ...
- centos7虚拟机开启端口后 外部不能访问的问题
转载 https://blog.csdn.net/u012045045/article/details/104219823 虚拟机新开了5005端口,系统内部是显示开了的(wget 192.168.4 ...
- C#从入门到放弃治疗一:初探C#世界
C#是一款高级的面向对象语言,运行于.NET framework之上的高级程序设计语言.其语言规范和,语法和java有着惊人的类似之处.所以如果你在学习C#之前有着java的基础,你将快速地入门.当然 ...