求出无向图的所有边双联通分量,然后缩点就成了一颗树。

然后我们选取最大的那个边双联通分量作为根,这样我们就可以确定所有割边的方向了。

对于边双联通分量里面的边,我们随便dfs一下就可以把它变成强连通分量,方向也就确定了。

 #include <bits/stdc++.h>
using namespace std; vector<int> G[];
vector<pair<int, int>> G2[];
set<pair<int, int>> bridge;
set<pair<int, int>> ansset;
pair<int, int> old[];
int vis[];
int dfn[];
int low[];
int tag[]; void get_bridge(int cur, int father, int dep)
{
vis[cur] = ;
dfn[cur] = low[cur] = dep;
int children = ;
for (auto to : G[cur])
{
if (to != father && vis[to] == )
{
if (dfn[to] < low[cur])
low[cur] = dfn[to];
}
if (vis[to] == )
{
get_bridge(to, cur, dep + );
children++;
if (low[to] < low[cur])
low[cur] = low[to];
if (low[to] > dfn[cur])
bridge.insert({cur, to}), bridge.insert({to, cur});
}
}
vis[cur] = ;
} int dfs(int u, int tot)
{
int cnt = ;
vis[u] = true;
tag[u] = tot;
for (auto to : G[u])
{
if (ansset.find({u, to}) == ansset.end() && ansset.find({to, u}) == ansset.end() && bridge.find({u, to}) == bridge.end())
{
ansset.insert({u, to});
if (!vis[to])
cnt += dfs(to, tot);
}
}
return cnt;
} void dfs2(int cur, int fa)
{
for (auto e : G2[cur])
{
int nxt = tag[e.second];
if (nxt != fa)
{
ansset.insert({e.second, e.first});
dfs2(nxt, cur);
}
}
} int main()
{
int n, m;
scanf("%d%d", &n, &m);
int u, v;
for (int i = ; i < m; i++)
{
scanf("%d%d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
old[i] = {u, v};
}
get_bridge(, -, );
memset(vis, , sizeof(vis));
int ans = ;
int tot = ;
int idx = ;
for (int i = ; i <= n; i++)
{
if (!vis[i])
{
int siz = dfs(i, ++tot);
if (siz > ans)
ans = siz, idx = tot;
}
}
for (auto e : bridge)
G2[tag[e.first]].push_back(e);
dfs2(idx, -);
printf("%d\n", ans);
for (int i = ; i < m; i++)
{
if (ansset.find(old[i]) == ansset.end())
printf("%d %d\n", old[i].second, old[i].first);
else
printf("%d %d\n", old[i].first, old[i].second);
}
return ;
}

Codeforces732F Tourist Reform的更多相关文章

  1. 732F Tourist Reform

    // CF 732F Tourist Reform // 思路:两遍tarjan // 找强联通分量 #include <bits/stdc++.h> using namespace st ...

  2. CodeForces 732F Tourist Reform

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

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

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

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

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

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

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

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

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

  7. 【codeforces 732F】Tourist Reform

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

  8. CF732F Tourist Reform(边双联通)

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

  9. CF732F Tourist Reform[边双缩点]

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

随机推荐

  1. android存储訪问框架Storage Access Framework

    在了解storage access framework之前.我们先来看看android4.4中的一个特性.假设我们希望能选择android手机中的一张图片,通常都是发送一个Intent给对应的程序.一 ...

  2. MRP Force Reservation的作用

    生产单根据BOM计算出相应的物料需求,生产领料单stock.picking ( internal moves) Stock.picking使用工作流自动计算库存量,如果库存量够,则使用 test_as ...

  3. python的pexpect模块

    Pexpect 是 Don Libes 的 Expect 语言的一个 Python 实现,是一个用来启动子程序,并使用正则表达式对程序输出做出特定响应,以此实现与其自动交互的 Python 模块. P ...

  4. 项目Alpha冲刺(团队8/10)

    项目Alpha冲刺(团队8/10) 团队名称: 云打印 作业要求: 项目Alpha冲刺(团队) 作业目标: 完成项目Alpha版本 团队队员 队员学号 队员姓名 个人博客地址 备注 221600412 ...

  5. Android Webview的测试

    1.查看当前的所有窗口: Set contexts= driver.getContextHandles(); System.out.println(contexts); 打印出当前所有的窗口 Set& ...

  6. 甘特图——Excel搞定

    1. 甘特图 概念 甘特图就是条形图的一种. 甘特图是基于作业排序的目的,将活动与时间联系起来的最早尝试之中的一个. 这是什么意思呢?也就是说甘特图用来表示什么时间做什么事情,相当于一个计划安排.并且 ...

  7. TC SRM 582 DIV 2

    Rating又跌了,第二个题,没想好就乱开始乱写了.. 我写乱搞贪心,没过...如果总人数很多judge函数写的不好,DIV2数据很水,直接暴力就行. #include <cstring> ...

  8. bash命令中的两个横

    它是一种标记.命令中的连续的两个横表明选项已经结束了,两个横后面的内容就是参数了,不再是选项了.

  9. 登录日志的访问日志的 统计 MapReduce

    登录日志的访问日志的 统计    MapReduce <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-commo ...

  10. centreon问题总结

    1.SNMP TABLE ERROR : Requested table is empty or does not exist 这是SNMP的服务端查询客服端失败,失败的原理是权限不足 解决办法: v ...