cf C. Valera and Elections
http://codeforces.com/contest/369/problem/C
先见边,然后dfs,在回溯的过程中,如果在这个点之后有多条有问题的边,就不选这个点,如果没有而且连接这个点的边还是有问题的边,这个点就是所求的点。
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 200000
using namespace std; int head[maxn],e,cnt,n;
int ans[maxn];
bool vis[maxn];
int point[maxn];
struct node
{
int u,v,w;
int next;
} p[maxn]; void add(int u,int v,int w)
{
p[e].u=u;
p[e].v=v;
p[e].w=w;
p[e].next=head[u];
head[u]=e++;
} void cls()
{
memset(head,-,sizeof(head));
memset(vis,false,sizeof(vis));
memset(ans,,sizeof(ans));
e=;
cnt=;
} int dfs(int u,int flag)
{
vis[u]=;
for(int i=head[u]; i!=-; i=p[i].next)
{
int v=p[i].v,w=p[i].w;
if(!vis[v])
{
ans[u]+=dfs(v,w);
}
}
if(flag==||ans[u]>=)
{
if(ans[u]==)
point[cnt++]=u;
return ;
}
return ;
} int main()
{
while(scanf("%d",&n)!=EOF)
{
cls();
for(int i=; i<=n-; i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
add(a,b,c);
add(b,a,c);
}
dfs(,);
printf("%d\n",cnt);
for(int i=; i<cnt; i++)
{
if(i==) printf("%d",point[i]);
else printf(" %d",point[i]);
}
printf("\n");
}
return ;
}
cf C. Valera and Elections的更多相关文章
- CF 369C . Valera and Elections tree dfs 好题
C. Valera and Elections The city Valera lives in is going to hold elections to the city Parliament ...
- CodeForces - 369C - Valera and Elections
369C - Valera and Elections 思路:dfs,对于搜索到的每个节点,看他后面有没有需要修的路,如果没有,那么这个节点就是答案. 代码: #include<bits/std ...
- Codeforces 369 C Valera and Elections
Valera and Elections 题意:现在有n个候选人, 有n-1条路, 如果选择了这个候选人, 这个候选人就会将从自己这个城市到1号城市上所有坏的路都修复一下,现在求最小的候选人数目, 如 ...
- CF 441E Valera and Number
CF 441E Description 一共执行\(k\)次,每次有\(p\%\)把\(x * 2\),有\((100 - p)\%\)把\(x + 1\).问二进制下\(x\)末尾期望\(0\)的个 ...
- cf E. Valera and Queries
http://codeforces.com/contest/369/problem/E 题意:输入n,m; n 代表有多少个线段,m代表有多少个询问点集.每一个询问输出这些点的集合所占的线段的个数. ...
- cf D. Valera and Fools
http://codeforces.com/contest/369/problem/D 标号最小的两个人会有四种状态:a活b活,a死b活,a活b死,a死b死:按照这四种状态dfs就可以求出最后的数量. ...
- cf B. Valera and Contest
http://codeforces.com/contest/369/problem/B 先对k个处理,先处理sk%k个为sk/k+1,如果sk/k==0,k个数都为sk/k:对与剩下的数也按照同样的方 ...
- CF(441D Valera and Swaps)置换群
题意:1-n的一个排列, p2, ..., pn,f(p)的定义是此排列要交换最少的数对能够回到原排列1,2,3,4...n.给一个排列p.要将其变换成f值为m的排列,问至少要交换几个数对,并输出字典 ...
- 369C Valera and Elections
http://codeforces.com/problemset/problem/369/C 树的遍历,dfs搜一下,从根节点搜到每个分叉末尾,记录一下路况,如果有需要修复的,就把分叉末尾的节点加入答 ...
随机推荐
- C++中的string类(1)
http://blog.sina.com.cn/s/blog_51409e8f01009h7g.html 前言: string 的角色1 string 使用1.1 充分使用string 操作符1.2 ...
- [置顶] 【Git入门之十】Rebase操作
原创作品,转载请标明:http://blog.csdn.net/jackystudio/article/details/12309627 Rebase,衍合?变基?唉,我也不知道要怎么翻译合适...变 ...
- weblogic 的应用 常见问题处理 db2 链接不上(转载)
xingkaistart weblogic10之Failed to initialize the application 'wss-1-1' due to error weblogic. Weblog ...
- js函数收藏:获取cookie值
//先设置一段子cookie var d = new Date(); d.setMonth(d.getMonth() + 1); d = d.toGMTString(); var a = " ...
- UVA 714 Copying Books 最大值最小化问题 (贪心 + 二分)
Copying Books Before the invention of book-printing, it was very hard to make a copy of a book. A ...
- BZOJ 3110 ZJOI 2013 K大数查询 树套树(权值线段树套区间线段树)
题目大意:有一些位置.这些位置上能够放若干个数字. 如今有两种操作. 1.在区间l到r上加入一个数字x 2.求出l到r上的第k大的数字是什么 思路:这样的题一看就是树套树,关键是怎么套,怎么写.(话说 ...
- 二、Solr安装(Tomcat)
安装环境 Windows 7 64bit Apache-tomcat-8.0.9-windows-x64 Solr-4.9.0 JDK 1.8.0_05 64bit 安装步骤 Tomcat和JDk的安 ...
- HashMap的分析(转)
一.HashMap概述 HashMap基于哈希表的 Map 接口的实现.此实现提供所有可选的映射操作,并允许使用 null 值和 null 键.(除了不同步和允许使用 null 之外,HashMap ...
- i春秋30强挑战赛pwn解题过程
80pts: 栈溢出,gdb调试发现发送29控制eip,nx:disabled,所以布置好shellcode后getshell from pwn import * #p=process('./tc1' ...
- Spinner( 微调) 组件
本节课重点了解 EasyUI 中 Spinner(微调)组件的使用方法,这个组件依赖于ValidateBox(验证框)组件. 一. 加载方式Spinner(微调)组件是其他两款高级微调组件的基础组件, ...