CodeForces 732F Tourist Reform
来源:互联网 发布:我欲封天翅膀进阶数据 编辑:程序博客网 时间:2024/06/05 14:32
题意:
给一个无向无重边无自环的连通图,问:如果把每条边确定一个方向(变成有向图),那么在这个图中,所有点能到达的点的个数中的最小值最大是多少。
分析:
最终的图缩点以后就是一个拓扑结构,那么一定有一个点是只能到达他本身,如果这个点是一个强连通块的话,答案就是这个强连通块内节点的个数。那么找一个强连通块内部节点个数最大的强连通块,然后
代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <string>#include <map>#include <vector>#include <set>#include <queue>#include <stack>#include <algorithm>using namespace std;typedef long long LL;typedef pair <int, int> PII;typedef vector <int> VI;#define FOR(i, x, y) for(int i = x; i < y; ++ i)#define IFOR(i, x, y) for(int i = x; i > y; -- i)#define pb push_back#define mp make_pair#define fi first#define se second#define lrt rt<<1#define rrt rt<<1|1#define lson rt<<1, l, mid#define rson rt<<1|1, mid+1, rLL quickpow(LL a, LL n, LL mod) { LL res = 1; while(n) { if(n&1) res = res*a%mod; a = a*a%mod; n >>= 1; } return res;}const int maxn = 400005;const int inf = 0x3fffffff;int n, m;int dfn[maxn], low[maxn], tot;int head[maxn], e_cnt;void init() { FOR(i, 1, n+1) head[i] = -1; FOR(i, 1, n+1) dfn[i] = low[i] = 0; e_cnt = 0;}struct Edge{ int v, w; int nt; Edge() {} Edge(int vv, int ww, int nn) : v(vv), w(ww), nt(nn) {}}e[maxn<<1];PII mat[maxn];void addedge(int u, int v, int w) { e[e_cnt] = Edge(v, w, head[u]); head[u] = e_cnt++;}int s[maxn], ans, rt;void dfs(int u, int fa) { low[u] = dfn[u] = ++ tot; s[++s[0]] = u; for(int i = head[u]; i != -1; i = e[i].nt) { int v = e[i].v; if(v == fa) continue; if(!dfn[v]) { mat[e[i].w] = mp(v, u); dfs(v, u); low[u] = min(low[u], low[v]); } else { mat[e[i].w] = mp(u, v); low[u] = min(low[u], dfn[v]); } } if(dfn[u] == low[u]) { int res = 1; while(s[s[0]] != u) { ++ res; -- s[0]; } -- s[0]; if(ans < res) {ans = res; rt = u;} }}int main() { while(~scanf("%d%d", &n, &m)) { int u, v; init(); FOR(i, 0, m) { scanf("%d%d", &u, &v); addedge(u, v, i); addedge(v, u, i); } s[0] = 0; tot = 0; ans = 1; dfs(1, -1); memset(dfn, 0, sizeof(dfn)); s[0] = 0; tot = 0; ans = 1; dfs(rt, -1); printf("%d\n", ans); FOR(i, 0, m) printf("%d %d\n", mat[i].fi, mat[i].se); } return 0;}
0 0
- CodeForces 732F Tourist Reform
- codeforces 732F Tourist Reform
- CODEFORCES 732F Tourist Reform
- [CF 732F]Tourist Reform
- CodeForces 732 F.Tourist Reform(边双连通分量)
- Codeforces 732F Tourist Reform【思维+边双联通+Dfs处理后继问题】好题!
- 【CF 732F】 Tourist Reform(割边+dfs)
- codeforces round 377 div2 F Tourist Reform tarjan求边双连通分量
- Codeforces All-Ukrainian School Olympiad in Informatics F.Tourist
- codeforces732F Tourist Reform(边双连通分量)
- codeforces 659 E New Reform
- codeforces 659E New Reform
- CodeForces 659E New Reform
- codeforces 659E New Reform
- codeforces 659E New Reform
- CodeForces 659E New Reform
- codeforces 732F
- Codeforces 732F tarjan
- 类、对象、包
- exec函数族
- okhttp框架 工具类
- LintCode 正则表达式匹配
- hdoj4741 求空间中不平行的两条直线的最短距离及最短线段与两直线的交点
- CodeForces 732F Tourist Reform
- 输入一个不超过12位的整数,转化为人民币的读法
- Python3学习四之基本编程
- Android相对布局属性
- 一个漂亮的php验证码类(分享)
- 项目的本质目标是什么?
- UML-状态图
- ASP.NET MVC2程序开发入门到精通系列课程 下载
- 备受国人追捧的曼谷Rama9 真的好吗?