李煜东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的更多相关文章

  1. CF 981C Useful Decomposition

    题面 题目大意 给定一棵树,要求划分出几条链,使这几条链交于一点. 解题思路 因为所有链都要交于一点,所以必须交于一个度数最多的点.这样就形成了一个菊花形.然后从这个点出发到它的子树,判断子树的度数是 ...

  2. codeforces 981 C.Useful Decomposition

    C. Useful Decomposition time limit per test 1 second memory limit per test 256 megabytes input stand ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. mongodb-replication set 复制集

    推荐一篇mongodb集群的博客 replication set 多台服务器维护相同的数据副本,提高服务的可用性 1.启动3个实例,且声明属于某复制集 mongod --port 27017 --db ...

  2. [bzoj1552\bzoj2506][Cqoi2014]robotic sort 排序机械臂_非旋转Treap

    robotic sort 排序机械臂 bzoj-1552 bzoj-2506 Cqoi-2014 题目大意:给定一个序列,让你从1到n,每次将[1,p[i]]这段区间反转,p[i]表示整个物品权值第i ...

  3. Spring MVC-概述(转载实践)

    以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_overview.htm 说明:示例基于Spring MVC 4.1.6. Spr ...

  4. IDEA入门级使用教程

    原文链接:https://blog.csdn.net/qq_31655965/article/details/52788374 最智能的IDE IDEA相对于eclipse来说最大的优点就是它比ecl ...

  5. ps -ef与ps aux的区别

    ps -ef与ps aux的区别 学习:http://www.linuxidc.com/Linux/2016-07/133515.htm ps aux可以查看其内存使用情况:

  6. JeeCG团队招聘啦!

    JeeCG团队招聘啦! 小团队攻坚,创业氛围浓厚.盼望有激情的你增加. 岗位描写叙述: 1,负责Jeecg.jeewx 微信管理系统相关的研发工作.2,高度參与整个产品设计.參与微信相关项目开发.3. ...

  7. 最长公共子序列 nlogn

    先来个板子 #include<bits/stdc++.h> using namespace std; , M = 1e6+, mod = 1e9+, inf = 1e9+; typedef ...

  8. viz.js操作流程

    1.下载依赖的js文件,并引入 <script src="${root }/resources/js/graphviz/viz.js"></script> ...

  9. DNS同时占用UDP和TCP端口53——传输数据超过512时候用tcp,DNS服务器可以配置仅支持UDP查询包

    DNS同时占用UDP和TCP端口53是公认的,这种单个应用协议同时使用两种传输协议的情况在TCP/IP栈也算是个另类.但很少有人知道DNS分别在什么情况下使用这两种协议. 先简单介绍下TCP与UDP. ...

  10. Java-杂项:Float 加减精度问题

    ylbtech-Java-杂项:Float 加减精度问题 1.返回顶部 1. java float 加减精度问题在取这个字段的时候转换成BigDecimal就可以了同时,BigDecimal是可以设置 ...