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. MyBatis里字段到枚举类型的转换/映射

    一.简介 我们在用MyBatis里,很多时间有这样一个需求:bean里有个属性是枚举,在DB存储时我们想存的枚举的代号,从DB拿出来时想直接映射成目标枚举类型,也即代号字段与Java枚举类的相互类型转 ...

  2. poj2063 Investment(多次完全背包)

    http://poj.org/problem?id=2063 多次完全背包~ #include <stdio.h> #include <string.h> #define MA ...

  3. 14条Yahoo(雅虎)十四条优化原则【转】

    请大家都能好好学习,不要像我一样一扫而过,好好的记下来!不仅仅是晓得一些CSS xhtml就好了,深刻认识到很多的东西需要学习的.很早就用Firebug,但是却没听说过Yslow,这叫不喜欢追求.希望 ...

  4. Codeforces Round #277.5 (Div. 2) --E. Hiking (01分数规划)

    http://codeforces.com/contest/489/problem/E E. Hiking time limit per test 1 second memory limit per ...

  5. [LeetCode] Search in Rotated Sorted Array I (33) && II (81) 解题思路

    33. Search in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unknown to you be ...

  6. 40 个重要的 HTML5 面试问题及答案

    本文将列出40个重要的HTML 5面试问题及答案,祝各位求职顺利. 目录 介绍 Canvas和SVG图形之间的区别是什么? 如何使用Canvas和SVG绘制矩形? 什么是CSS选择器? 如何使用ID值 ...

  7. Mapreduce运行过程分析(基于Hadoop2.4)——(一)

    1 概述 该瞅瞅MapReduce的内部执行原理了,曾经仅仅知道个皮毛,再不搞搞,不然怎么死的都不晓得.下文会以2.4版本号中的WordCount这个经典样例作为分析的切入点.一步步来看里面究竟是个什 ...

  8. Cocos2D-x权威指南: CCNode类方法:

    5.1.4 画图节点CCNode和图层CCLayer CCNode中提供的方法,在public块中的方法主要有下面几个部分: 1.针对节点显示的属性信息读写 2.针对节点变换的属性信息读写 3.针对子 ...

  9. [Angular 2] Using Promise to Http

    You can also use Promise for http: So for the service, you need to call toPromise() method: getVehic ...

  10. C++类的const成员函数、默认的构造函数、复制形参调用函数(转)

    C++类的const成员函数 double Sales_item::avg_price() const { } const关键字表明这是一个const成员函数,它不可以修改Sales_item类的成员 ...