图论水题但是没想到
2019-08-16 07:56:38来源:博客园 阅读 ()
图论水题但是没想到
Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems.
You are given a tree with nn nodes. In the beginning, 00 is written on all edges. In one operation, you can choose any 22 distinct leaves uu, vv and any real number xx and add xx to values written on all edges on the simple path between uu and vv.
For example, on the picture below you can see the result of applying two operations to the graph: adding 22 on the path from 77 to 66, and then adding −0.5−0.5 on the path from 44 to 55.
Is it true that for any configuration of real numbers written on edges, we can achieve it with a finite number of operations?
Leaf is a node of a tree of degree 11. Simple path is a path that doesn't contain any node twice.
Input
The first line contains a single integer nn (2≤n≤1052≤n≤105) — the number of nodes.
Each of the next n−1n−1 lines contains two integers uu and vv (1≤u,v≤n1≤u,v≤n, u≠vu≠v), meaning that there is an edge between nodes uu and vv. It is guaranteed that these edges form a tree.
Output
If there is a configuration of real numbers written on edges of the tree that we can't achieve by performing the operations, output "NO".
Otherwise, output "YES".
You can print each letter in any case (upper or lower).
Examples
Input2 1 2Output
YESInput
3 1 2 2 3Output
NOInput
5 1 2 1 3 1 4 2 5Output
NOInput
6 1 2 1 3 1 4 2 5 2 6Output
YES
Note
In the first example, we can add any real xx to the value written on the only edge (1,2)(1,2).
In the second example, one of configurations that we can't reach is 00 written on (1,2)(1,2) and 11 written on (2,3)(2,3).
Below you can see graphs from examples 33, 44:
#include<stdio.h> #include<iostream> #include<algorithm> #include<string.h> #include<vector> #include<cmath> #include<string> #include<map> #include<queue> using namespace std; #define INF 0x3f3f3f3f typedef long long ll; ll in[200001]; int main(){ ll n; while(cin>>n){ memset(in,0,sizeof(in)); for(ll i=1;i<=n-1;i++){ ll x,y; cin>>x>>y; in[x]++; in[y]++; } ll sign=0; for(ll i=1;i<=n;i++){ if(in[i]==2){ sign=1; break; } } if(sign==1){ cout<<"NO"<<endl; } else cout<<"YES"<<endl; } return 0; }
原文链接:https://www.cnblogs.com/akpower/p/11284887.html
如有疑问请与原作者联系
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- 【图论】几个例题~ 2020-04-14
- 【学习笔记】[图论]树的直径 2020-02-14
- 图论初步<蒟蒻专属文章> 2020-02-08
- Codeforces 939A题水题 2019-11-12
- codeforces467-A水题 2019-11-05
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash