【NOIP2010 模拟赛】晨跑路径
来源:互联网 发布:java return this 编辑:程序博客网 时间:2024/04/30 08:31
【NOIP2010 模拟赛】晨跑路径
Description
天天到部队,教官要求他们每天早上晨跑,从A农场跑到B农场。从A农场到B农场中有n-2个路口,分别标上号A农场为1号,B农场为n号,路口分别为2..n-1号,从A农场到B农场有很多条路径可以到达,而教官发现有的路口是必须经过的,即每一条路径都经过的路口,教官要把他们记录下来,这样教官就可以先到达那个路口,观察天天有没有偷懒,而你的任务就是找所有必经路口。
Input
第一行两个用空格隔开的整数n(3<=n<=2000)和e(1<=e<=8000)。
接下来从第2行到第e+1行,每行两个用空格隔开的整数p和q,表示路口p和q之间连通。
输入数据保证必经路口一定存在,并且每个路口都和A农场,B农场相连通。
Output
第一行一个整数m,表示必经路口的数目。
第二行按从小到大的顺序依次输出每个必经路口的编号,每两个数之间用空格隔开。
注意:不包括起点和终点
Sample Input
6 6
1 2
2 4
2 3
3 5
4 5
5 6
Sample Output
2
2 5
Source
搜索 ,图论
Solution
就是求割点的个数,可以用tarjan(无奈不会啊),于是就用了很暴力的暴力
直接枚举每一个点,check将其断开后是否可以到达终点,能到达即不是割点,不能到达即满足情况,将其记录存入数组,最后一次性输出即可
Code
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>#include <stack>#include <map>#include <vector>#include <queue>#define L 5000#define LL long longusing namespace std;struct node { int nxt, to;} x[L * 3];int n, e, a, b, cnt, head[L], ans[L], num;bool vis[L], bj;inline void add(int from, int to) { x[++cnt].nxt = head[from]; x[cnt].to = to; head[from] = cnt;}inline void dfs(int a) { for (int i = head[a]; i; i = x[i].nxt) if (!vis[x[i].to]) { if (x[i].to == n) {bj = false; return ;} vis[x[i].to] = true; dfs(x[i].to); }}int main() { freopen("running.in", "r", stdin); freopen("running.out", "w", stdout); scanf("%d %d", &n, &e); for (int i = 1; i <= e; ++i) { scanf("%d %d", &a, &b); add(a, b), add(b, a); } for (int i = 2; i < n; ++i) { bj = true; memset(vis, false, sizeof(vis)); vis[i] = true; dfs(1); if (bj) ans[++num] = i; } printf("%d\n", num); for (int i = 1; i <= num; ++i) printf("%d ", ans[i]); return 0;}
Summary
考试的时候想了很暴力的暴力:找到方案总数,以及所用方案中每个点被经过的次数,如果经过的次数等与方案总数,那么这个点就是必须经过的点,结果只有10分
后来开始求割点,结果数组开小了WA了一次,把数组开大就A了
0 0
- 【NOIP2010 模拟赛】晨跑路径
- 2017-03-11 【NOIP2010 模拟赛】晨跑路径
- 【noip2010模拟赛】classroom
- 中山纪念中学 NOIP2010模拟赛
- [NOIP2010]机器翻译 队列+模拟
- 【模拟】【NOIP2010】机器翻译 translate
- [模拟][NOIP2010] 机器翻译
- noip2010 机器翻译 (模拟)
- [noip2010模拟] 保龄球
- 【CJOJ P1957】【NOIP2010冲刺十模拟赛】数字积木
- 【NOIP2010冲刺十二模拟赛】奶牛晒衣服
- 【NOIP2010】【模拟】T1 机器翻译 题解
- [NOIP2010]三国游戏 T4 模拟
- noip2010 接水问题 (模拟)
- NOIP2010 提高组 机器翻译_队列+模拟
- NOIp2010
- NOIP2010
- [noip模拟]四道题 noip2010 机器翻译 noip2010 乌龟棋 noip 关押罪犯 noip 引水入城
- BZOJ 4012: [HNOI2015]开店 -- 动态树分治
- Java: synchronized详解,静态同步方法,普通同步方法,同步代码块
- JSP中文乱码解决方法
- Spring 对JDBC的支持
- HDU-3045 Picnic Cows 【DP+斜率优化】
- 【NOIP2010 模拟赛】晨跑路径
- 设计模式
- HDU 2154 跳舞毯
- Android jni开发资料--NDK环境搭建和应用(深入浅出)
- 2023.求平均成绩
- Myeclipse--ibator工具
- http://www.imagemagick.org/script/install-source.php#windows
- |算法讨论|单调队列 学习笔记
- hdu3280(不是区间DP的解法 很好理解)