Educational Codeforces Round 78 (Rated for Div. 2)E(构造,DFS)
DFS,把和当前结点相连的点全都括在当前结点左右区间里,它们的左端点依次++,然后对这些结点进行DFS,优先对左端点更大的进行DFS,这样它右端点会先括起来,和它同层的结点(后DFS的那些)的区间会把它括起来,这样它们就不会相交了。
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int cnt=;
vector<int>v[];
int l[],r[];
void dfs(int x,int fa){
for(int i=;i<v[x].size();++i)
if(v[x][i]!=fa)
l[v[x][i]]=++cnt;
r[x]=++cnt;
for(int i=v[x].size()-;i>=;--i)
if(v[x][i]!=fa)
dfs(v[x][i],x);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
for(int i=;i<n;++i){
int x,y;
cin>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
dfs(,);
l[]=;
for(int i=;i<=n;++i)
cout<<l[i]<<" "<<r[i]<<"\n";
return ;
}
Educational Codeforces Round 78 (Rated for Div. 2)E(构造,DFS)的更多相关文章
- Educational Codeforces Round 78 (Rated for Div. 2) D. Segment Tree
链接: https://codeforces.com/contest/1278/problem/D 题意: As the name of the task implies, you are asked ...
- Educational Codeforces Round 78 (Rated for Div. 2) C. Berry Jam
链接: https://codeforces.com/contest/1278/problem/C 题意: Karlsson has recently discovered a huge stock ...
- Educational Codeforces Round 78 (Rated for Div. 2) B. A and B
链接: https://codeforces.com/contest/1278/problem/B 题意: You are given two integers a and b. You can pe ...
- Educational Codeforces Round 78 (Rated for Div. 2) A. Shuffle Hashing
链接: https://codeforces.com/contest/1278/problem/A 题意: Polycarp has built his own web service. Being ...
- 【cf比赛记录】Educational Codeforces Round 78 (Rated for Div. 2)
比赛传送门 A. Shuffle Hashing 题意:加密字符串.可以把字符串的字母打乱后再从前面以及后面接上字符串.问加密后的字符串是否符合加密规则. 题解:字符串的长度很短,直接暴力搜索所有情况 ...
- Educational Codeforces Round 78 (Rated for Div. 2)B. A and B(1~n的分配)
题:https://codeforces.com/contest/1278/problem/B 思路:还是把1~n分配给俩个数,让他们最终相等 假设刚开始两个数字相等,然后一个数字向前走了abs(b- ...
- Educational Codeforces Round 78 (Rated for Div. 2)
A题 给出n对串,求s1,是否为s2一段连续子串的重排,串长度只有100,从第一个字符开始枚举,sort之后比较一遍就可以了: char s1[200],s2[200],s3[200]; int ma ...
- Educational Codeforces Round 78 (Rated for Div. 2) --补题
链接 直接用数组记录每个字母的个数即可 #include<bits/stdc++.h> using namespace std; int a[26] = {0}; int b[26] = ...
- Educational Codeforces Round 78 (Rated for Div. 2) 题解
Shuffle Hashing A and B Berry Jam Segment Tree Tests for problem D Cards Shuffle Hashing \[ Time Lim ...
- Educational Codeforces Round 78 (Rated for Div. 2) C - Berry Jam(前缀和)
随机推荐
- win10驱动签名禁用与启动
禁用:https://jingyan.baidu.com/article/624e74594dbc8d34e8ba5aa6.html?qq-pf-to=pcqq.c2c 启用或恢复:https://z ...
- const真有点烦
在C++中const代替#define的操作,当定义一个const时必须附一个值给它:const int size = 100;通常C++编译器不为const创建存储空间,相反它把这个定义保存在符号表 ...
- python:删除文件及文件夹
#!/usr/bin/python# -*- coding:utf-8 -*- import os import shutil os.remove(path) #删除文件shutil.rmtree(p ...
- Web渗透测试思路整理
信息收集: 域名/IP 子域名列表 whois: 注册地址,注册人,联系方式等 whois反查: 同ip有哪些站点(旁注),同一个注册人注册了哪些域名 社工注册人信息 指纹识别: 操作系统及版本 数据 ...
- 1054 The Dominant Color
大致题意就是给出N行M列的元素,找出出现次数最多的元素并输出. #include<iostream> #include<unordered_map> using namespa ...
- LED Holiday Light - Holiday Lighting Maintenance Guide
If you are experiencing problems with LED holiday lighting, the following guides will provide advice ...
- 记录 shell学习过程(3) if 的格式
] #-e 为检测目录或文件是否存在 !为取反 then mkdir -v /tmp/ echo 'ok' fi if else if [ $USER == 'root' ] then echo 'h ...
- vs2015编译各种库
1.编译libcurl https://www.jianshu.com/p/f82d3d18da93
- 剑指offer 面试题. 滑动窗口的最大值
题目描述 给定一个数组和滑动窗口的大小,找出所有滑动窗口里数值的最大值.例如,如果输入数组{2,3,4,2,6,2,5,1}及滑动窗口的大小3,那么一共存在6个滑动窗口,他们的最大值分别为{4,4,6 ...
- Python3标准库:string通用字符串操作
1. string:通用字符串操作 string模块在很早的Python版本中就有了.以前这个模块中提供的很多函数已经移植为str对象的方法,不过这个模块仍保留了很多有用的常量和类来处理str对象. ...