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

  1. 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 ...

  2. CodeForces - 369C - Valera and Elections

    369C - Valera and Elections 思路:dfs,对于搜索到的每个节点,看他后面有没有需要修的路,如果没有,那么这个节点就是答案. 代码: #include<bits/std ...

  3. Codeforces 369 C Valera and Elections

    Valera and Elections 题意:现在有n个候选人, 有n-1条路, 如果选择了这个候选人, 这个候选人就会将从自己这个城市到1号城市上所有坏的路都修复一下,现在求最小的候选人数目, 如 ...

  4. CF 441E Valera and Number

    CF 441E Description 一共执行\(k\)次,每次有\(p\%\)把\(x * 2\),有\((100 - p)\%\)把\(x + 1\).问二进制下\(x\)末尾期望\(0\)的个 ...

  5. cf E. Valera and Queries

    http://codeforces.com/contest/369/problem/E 题意:输入n,m; n 代表有多少个线段,m代表有多少个询问点集.每一个询问输出这些点的集合所占的线段的个数. ...

  6. cf D. Valera and Fools

    http://codeforces.com/contest/369/problem/D 标号最小的两个人会有四种状态:a活b活,a死b活,a活b死,a死b死:按照这四种状态dfs就可以求出最后的数量. ...

  7. cf B. Valera and Contest

    http://codeforces.com/contest/369/problem/B 先对k个处理,先处理sk%k个为sk/k+1,如果sk/k==0,k个数都为sk/k:对与剩下的数也按照同样的方 ...

  8. CF(441D Valera and Swaps)置换群

    题意:1-n的一个排列, p2, ..., pn,f(p)的定义是此排列要交换最少的数对能够回到原排列1,2,3,4...n.给一个排列p.要将其变换成f值为m的排列,问至少要交换几个数对,并输出字典 ...

  9. 369C Valera and Elections

    http://codeforces.com/problemset/problem/369/C 树的遍历,dfs搜一下,从根节点搜到每个分叉末尾,记录一下路况,如果有需要修复的,就把分叉末尾的节点加入答 ...

随机推荐

  1. 【HDOJ】1332 LC-Display

    水题. #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 11 #defin ...

  2. BZOJ2091: [Poi2010]The Minima Game

    2091: [Poi2010]The Minima Game Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 243  Solved: 163[Subm ...

  3. HDOJ(HDU) 1555 How many days?(水题)

    Problem Description 8600的手机每天消费1元,每消费K元就可以获赠1元,一开始8600有M元,问最多可以用多少天? Input 输入包括多个测试实例.每个测试实例包括2个整数M, ...

  4. CCF 送货 + 欧拉路模板

    #include <bits/stdc++.h> using namespace std; stack<int> st; vector<]; ][]; ],cp[]; i ...

  5. HDU-3787(字符串模拟)

    Problem Description 给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开.现在请计算A+B的结果,并以正常形式输出.   Input 输入包含 ...

  6. ArcGIS加载高德、OSM和谷歌等地图

    1. 引言 网络地图对于我们来说已经不是什么新鲜事了,上面有各大互联网公司收集的海量的地理空间数据.一般网络地图的地图是以切片形式存在的,因此,本文重点讲述如何将这些网络切片地图加载并显示再ArcGI ...

  7. 【蓝桥杯】PREV-5 错误票据

    题目链接:gpid=T28">http://lx.lanqiao.org/problem.page? gpid=T28   历届试题 错误票据   时间限制:1.0s   内存限制:2 ...

  8. getChars的使用方法

    <%@ page contentType="text/html; charset=gb2312" %> <%@ page import="java.ut ...

  9. qt: flush: BitBlt failed

    "BitBlt" is a graphics accelerator function. The message is a warning, not an error. It te ...

  10. (原创)初识cordova(一)

    在公司做项目,发现有人在做大项目使用了cordova技术.做的是昆山的项目.之前听说过phonegap,也测试过,但是感觉效率不是很好,就没怎么研究,后来看他们做的项目还不错,于是想试一试. 搭建开发 ...