[CodeForces]981C Useful Decomposition
李煜东dalao今天给我们讲课了QwQ
ppt上一道题
英文题说一下题意吧,以后又看不懂了
将一棵树分割成多个简单路径,每个边只能在一条路径上,但至少有一个公共节点。
输出简单路径分割方法/No
由题易知,如果图不是一个菊花图的话,想搞成题意的样子至少要有环或者有的路径共用。
想到这儿代码搞一搞就行了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int N=1e5;
vector<int>s;
int n,ecnt,head[N],mx=0,ct;
struct Edge{
int to,nxt,val;
}e[N<<1];
int du[N];
void add(int bg,int ed) {
e[++ecnt].nxt=head[bg];e[ecnt].to=ed;head[bg]=ecnt;
}
int main() {
scanf("%d",&n);
int cnt=0;
for(int i=1,u,v;i<n;i++) scanf("%d%d",&u,&v),add(u,v),add(v,u),du[u]++,du[v]++;
for(int i=1;i<=n;i++) {
if(mx<du[i]) mx=du[i],ct=i;
if(du[i]>2 ) cnt++;
else if(du[i]==1)s.push_back(i);
if(cnt>1) {printf("No");return 0;}
}
puts("Yes");
if(!cnt) {
puts("1");
printf("%d %d",s[0],s[1]);return 0;
}
printf("%d\n",s.size());
for(int i=0;i<s.size();i++) printf("%d %d\n",ct,s[i]);
}
[CodeForces]981C Useful Decomposition的更多相关文章
- CF 981C Useful Decomposition
题面 题目大意 给定一棵树,要求划分出几条链,使这几条链交于一点. 解题思路 因为所有链都要交于一点,所以必须交于一个度数最多的点.这样就形成了一个菊花形.然后从这个点出发到它的子树,判断子树的度数是 ...
- codeforces 981 C.Useful Decomposition
C. Useful Decomposition time limit per test 1 second memory limit per test 256 megabytes input stand ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- ABCDE
ABCDE A-Artificial intelligence 人工智能 B-Block chain 区块链 C-Cloud 云 D-Big Data 大数据 E-Ecology 互联网生态是以互联网 ...
- structs实现三种action的方法
第一种:一般类,带有public String execute()方法. 另外一种:继承LoginActionInterface implements Action接口的类. 第三种:继承LoginA ...
- 省市区js三级联动(原创)
看了一些网上的js三级联动,但感觉不是缺这,就是少那,决定亲自操刀写了一个,现记录如下,以备后用! <!DOCTYPE html> <html> <head> &l ...
- SpringBoot中拦截器和过滤器的使用
一.拦截器 三种方式 继承WebMvcConfigurerAdapter spring5.0 以弃用,不推荐 实现WebMvcConfigurer 推荐 继承WebMvcConfiguratio ...
- A - Translation
Problem description The translation from the Berland language into the Birland language is not an ea ...
- getElementsByName使用
查了下手册,getElementsByName()不能提取没有name属性的标签.div标签本身没有name属性,所以不能被提取.有name标签的主要是各种input标签,所以默认情况下getElem ...
- MATLAB 2018a 下载安装
参考链接:https://www.youtube.com/watch?v=BJavEE9KIlY
- 使用eclipse,对spring boot 进行springloader或者devtool热部署失败处理方法
确定配置进行依赖和配置没有错误后. 调整spring boot 的版本,因为新版本对老版本的spring boot 不能使用. 改为: <groupId>org.springframewo ...
- H5 微信公众号 监听返回事件
/*-----监听返回事件-----*/ function pushHistory(returnUrl,currentUrl,currentTitle) { window.addEventListen ...
- 【Five-Minute Share】“为什么要选择自增型的主键”
我们在开发的时候经常会听到这样的建议:1. 设计数据库表的时候,要为每个表设置一个主键:2. 主键最好是跟业务无关的: 3. 最好是自增的: 于是,很多新入行的程序猿们把这些前辈们的教条拿来就用,每个 ...