// CF 732F Tourist Reform
// 思路:两遍tarjan
// 找强联通分量
#include <bits/stdc++.h>
using namespace std;
#define LL long long
typedef pair<int,int> pii;
const int inf = 0x3f3f3f3f;
const int N =41e5+;
#define clc(a,b) memset(a,b,sizeof(a))
const double eps = 1e-;
const int MOD = 1e9+;
void fre() {freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-;ch=getchar();}while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}return x*f;} int head[N],low[N],dfn[N],s[N];
int cnt,tot;
struct Edge{
int v,w,nt;
Edge(){}
Edge(int v_,int w_,int nt_):v(v_),w(w_),nt(nt_){}
}e[N<<]; void add(int u,int v,int w){
e[cnt]=Edge(v,w,head[u]);
head[u]=cnt++;
}
pii mat[N];
int rt;
int ans;
void tarjan(int u,int f){
low[u] = dfn[u] = ++ tot;
s[++s[]] = u;
for(int i = head[u]; i != -; i = e[i].nt) {
int v = e[i].v;
if(v == f) continue;
if(!dfn[v]) {
mat[e[i].w] = make_pair(v, u);
tarjan(v, u);
low[u] = min(low[u], low[v]);
}
else {
mat[e[i].w] = make_pair(u, v);
low[u] = min(low[u], dfn[v]);
}
}
if(dfn[u] == low[u]) {
int res = ;
while(s[s[]] != u) {
++ res;
-- s[];
}
-- s[];
if(ans < res) {ans = res; rt = u;}
}
} void init(){
clc(head,-);
tot=;
cnt=;
ans=;
}
int main(){
init();
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
add(u,v,i);
add(v,u,i);
}
s[]=;
tarjan(,-);
clc(dfn,);
tot=;
s[]=;
tarjan(rt,-);
printf("%d\n",ans);
for(int i=;i<=m;i++){
printf("%d %d\n",mat[i].first,mat[i].second);
}
return ;
}

732F Tourist Reform的更多相关文章

  1. CodeForces 732F Tourist Reform

    边双连通分量. 这题有一点构造的味道.一个有向图,经过强连通缩点之后会形成一个有向无环图. 如果将最大的强连通分量放在顶端,其余的强连通分量都直接或间接指向他,那么这样就构造出了符合要求的图. 接下来 ...

  2. CF 732F Tourist Reform——v-SCC+dfs

    题目:http://codeforces.com/contest/732/problem/F 给无向图定向使得从每个点出发能去的点数最小值最大. SCC.点内部dfs定向.点间以siz最大的为起点反向 ...

  3. Codeforces 732F. Tourist Reform (Tarjan缩点)

    题目链接:http://codeforces.com/problemset/problem/732/F 题意: 给出一个有n个点m条边的无向图,保证联通,现在要求将所有边给定一个方向使其变成有向图,设 ...

  4. 【codeforces 732F】Tourist Reform

    [题目链接]:http://codeforces.com/contest/732/problem/F [题意] 给你一张无向图; n个点,m条边; 让你把这张图改成有向边 然后定义r[i]为每个点能够 ...

  5. Codeforces Round #377 (Div. 2) F - Tourist Reform

    前言:关于如何求双连通分量,我们可以在tarjan搜索时标记下所有桥的位置(双连通分量(可以认为是没有桥的无向图图)即可通过删去所有桥得到),那么怎么找桥呢,对于每一条搜索到的边u->x,如果l ...

  6. Codeforces732F Tourist Reform

    求出无向图的所有边双联通分量,然后缩点就成了一颗树. 然后我们选取最大的那个边双联通分量作为根,这样我们就可以确定所有割边的方向了. 对于边双联通分量里面的边,我们随便dfs一下就可以把它变成强连通分 ...

  7. CF732 F Tourist Reform——边双连通分量

    题目:http://codeforces.com/contest/732/problem/F 首先把边双缩点,边双内部 dfs 一个顺序一定是可以从每个点走到边双内部所有点的,因为它是以环为基本单位: ...

  8. CF732F Tourist Reform(边双联通)

    题意 在一张有向图中,设 ri 为从点 i 出发能够到达的点的数量. 定义有向图的“改良值”为 ri 的最小值. 现给出一张无向图,要求给每条边定一个方向,使产生的有向图“改良值”最大. 输出 最大改 ...

  9. CF732F Tourist Reform[边双缩点]

    题意:给无向图每一条边定向,使得每个点可达点数$R_i$最小值尽可能大,求方案. 条件反射想到二分答案,然后看怎么检验,发现要让所有点$R_i$大于等于某一个值,首先我们关注某些特殊的子图:如果有环的 ...

随机推荐

  1. 在Spring-boot中,为@Value注解添加从数据库读取properties支持

    一般我们会把常用的属性放在工程的classpath文件夹中,以property,yaml或json的格式进行文件存储,便于Spring-boot在初始化时获取. @Value则是Spring一个非常有 ...

  2. thinkphp 标签嵌套

    模板引擎支持标签的多层嵌套功能,可以对标签库的标签指定可以嵌套. 直线电机价格 系统内置的标签中,volist.switch.if.elseif.else.foreach.compare(包括所有的比 ...

  3. luogu P1332 血色先锋队[bfs]

    题目描述 巫妖王的天灾军团终于卷土重来,血色十字军组织了一支先锋军前往诺森德大陆对抗天灾军团,以及一切沾有亡灵气息的生物.孤立于联盟和部落的血色先锋军很快就遭到了天灾军团的重重包围,现在他们将主力只好 ...

  4. 最大流——hdu4292(类似poj3281 带间隔的流)

    #include<bits/stdc++.h> using namespace std; #define maxn 100005 #define inf 0x3f3f3f3f ]; int ...

  5. kubernetes istio的快速安装和使用例子

    安装 [root@master ~]# wget https://github.com/istio/istio/releases/download/1.1.5/istio-1.1.5-linux.ta ...

  6. day 49 Bootstrap框架和inconfont、font-awesome使用

    Bootstrap框架和inconfont.font-awesome使用   iconfont的使用:https://www.cnblogs.com/clschao/articles/10387580 ...

  7. 《DSP using MATLAB》Problem 8.39

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  8. low版九九乘法表

    # while循环实现九九乘法表num_one = 1while num_one <= 9: num_two = 1 while num_two <= num_one: print(&qu ...

  9. Eclipse添加git插件及操作

    注册账号新建仓库 在Github已经注册成功自己的账号 新建一个仓库 创建成功后记住url: 安装Git插件 首先像安装Pydev一样 点击help的Install New Software 点击Ad ...

  10. vue组件间通信用例

    父组件传值给子组件 -- 以封装公用slide组件为例 父组件 <template> <section class="banner"> <slide ...