Codeforces Round #377 (Div. 2) F
来源:互联网 发布:衣服好看又好的淘宝店 编辑:程序博客网 时间:2024/05/16 03:54
题意:
给定一张n个点m条边的无向图,保证连通,无自环,要求给边定向,定义一个点的权值ri,为从这个点出发,能够到达的点的数目,求一个使得最小ri最大的方案并打印出
solution:
对于双连通分量,一定能找出一种方案,使得这个边双中的任意两点能互达(废话--),那么对于这个边双,这样定向显然是最优的。。
把无向图中所有边双缩点,那么剩下一棵树,树上的边就是原图中的桥边,尝试给桥边定向,可以发现,a->b这条边,可以给b贡献sizea,以及所有能走到a的点贡献sizea,然后,桥边的定向总是能搞出一条条链,而每条链的尽头的那个点,一定没办法享受任何一个双连通分量的贡献!那么显然,我们让原本size最大的那个点当这样的点,一定是最优方案
至于边双内部的边的定向,任意找一个点,一直dfs,按照dfs的顺序定向即可。。。(感觉很显然啊--)
#include<iostream>#include<cstdio>#include<queue>#include<vector>#include<bitset>#include<algorithm>#include<cstring>#include<map>#include<stack>#include<set>#include<cmath>#include<ext/pb_ds/priority_queue.hpp>using namespace std;const int maxn = 4E5 + 40;struct E{int to,num;E(){}E(int to,int num): to(to),num(num){}};int n,m,dfs_clock,tot,au[maxn],av[maxn],low[maxn],dfn[maxn],siz[maxn],bel[maxn],p[maxn];bool brg[maxn],v1[maxn],v2[maxn],v3[maxn];vector <E> v[maxn];void Mark(int x,int fa){bel[x] = tot;++siz[tot];for (int i = 0; i < v[x].size(); i++) {int to = v[x][i].to;if (to == fa) continue;int num = v[x][i].num;if (brg[num]) continue;if (!au[num]) {au[num] = x;av[num] = to;}if (v2[to]) continue;v2[to] = 1;Mark(to,x);}}void Dfs(int x,int fa){dfn[x] = low[x] = ++dfs_clock;for (int i = 0; i < v[x].size(); i++) {int to = v[x][i].to;if (to == fa) continue;if (!v1[to]) {v1[to] = 1; Dfs(to,x);low[x] = min(low[x],low[to]);if (low[to] == dfn[to]) {brg[v[x][i].num] = 1;v2[p[++tot] = to] = 1;Mark(to,0);}}else low[x] = min(low[x],low[to]);}}void Dfs2(int x,int fa){for (int i = 0; i < v[x].size(); i++) {int to = v[x][i].to;if (to == fa) continue;int num = v[x][i].num;if (brg[num] && !au[num]) {au[num] = to;av[num] = x;}if (v3[to]) continue;v3[to] = 1;Dfs2(to,x);}}int main(){#ifdef DMCfreopen("DMC.txt","r",stdin);#endifcin >> n >> m;for (int i = 1; i <= m; i++) {int x,y; scanf("%d%d",&x,&y);v[x].push_back(E(y,i));v[y].push_back(E(x,i));}v1[1] = 1;Dfs(1,0);v2[p[++tot] = 1] = 1;Mark(1,0);int s,ans = 0;for (int i = 1; i <= tot; i++)if (siz[i] > ans) ans = siz[i],s = p[i];v3[s] = 1;Dfs2(s,0);cout << ans << endl;for (int i = 1; i <= m; i++)printf("%d %d\n",au[i],av[i]);return 0;}
0 0
- Codeforces Round #377 (Div. 2) F
- Codeforces Round #377 (Div. 2)(D.E.F)
- Codeforces Round #277.5 (Div. 2) F
- Codeforces Round #279 (Div. 2) F
- Codeforces Round #279 (Div. 2) F
- Codeforces Round #279 (Div. 2) B F
- Codeforces Round #277.5 (Div. 2)F题
- Codeforces Round #322 (Div. 2) F
- Codeforces Round #386 (Div. 2) F
- Codeforces Round #441 Div. 2 E,F
- Codeforces Round #442 (Div. 2) 877 F
- Codeforces Round 864F (Codeforces Round #436 Div. 2) F. Cities Excursions tarjan判环
- Codeforces Beta Round #95 (Div. 2) F - Present to Mom
- Codeforces Round #271 (Div. 2)F. Ant colony(线段树)
- Codeforces Round #277.5 (Div. 2) F. Special Matrices
- Codeforces Round #279 (Div. 2) F. Treeland Tour
- Codeforces Round #Pi (Div. 2) F. Mausoleum DP
- DP Codeforces Round #322 (Div. 2) F. Zublicanes and Mumocrates
- 深入解析AsyncTask(doInBackground不工作)
- Atitit atiuse软件系列
- php源码之路第二章第二节(SAPI概述之FastCGI)
- Python源码学习(1)-VS2008编译python源码
- Redis之(七)主从同步与集群管理
- Codeforces Round #377 (Div. 2) F
- hdu1159_Common Subsequence
- docker筑基篇-03-使用docker-commit构建自己的镜像
- Java数据结构内容整理
- Atitit.attilax重要案例 项目与解决方案与成果 v6 qa15
- 2016/10/18
- Java程序优化-设计优化
- mysql中count(1)与count(*)比较
- qqzoneQQ空间漏洞扫描器的设计attilax总结