当前位置:网站首页>[ARC092D] Two Faced Edges
[ARC092D] Two Faced Edges
2022-07-30 13:41:00 【Heart is cold month】
[ARC092D] Two Faced Edges
Consider the nature of strongly connected components,That is, any two of them u , v u,v u,v 都有一条 u → v u\to v u→v 的路径,There is also one v → u v\to u v→u 的路径.
Consider the situation where the number of strong-connection components at the turning edge changes,There is an edge as ( u , v ) (u,v) (u,v):
- 有an opposite side ( v , u ) (v,u) (v,u) 且除了 ( u , v ) (u,v) (u,v) 外无一条从 u u u 到 v v v 的路径,The number of strong connectivity components is reduced.
- 无反向边 ( v , u ) (v,u) (v,u) 且除了 ( u , v ) (u,v) (u,v) 外有一条从 u u u 到 v v v 的路径,The number of strong connectivity components is increased.
That is, the number does not change:
- 有an opposite side ( v , u ) (v,u) (v,u) 且除了 ( u , v ) (u,v) (u,v) 外有一条从 u u u 到 v v v 的路径,The number of strong connectivity components is reduced.
- 无an opposite side ( v , u ) (v,u) (v,u) 且除了 ( u , v ) (u,v) (u,v)无一条从 u u u 到 v v v 的路径,The number of strong connectivity components is reduced.
总结一下,Just consider the following factors:
- Whether the current edge has an opposite edge,The maintenance method is relatively simple.
- Whether there is a slave other than the current edge u u u 到 v v v 的路径,Consider dyeing judgment,method does not speak.
时间复杂度 O ( n m ) \mathcal O(nm) O(nm),可优化.
#include<bits/stdc++.h>
using namespace std;
//#define int long long
typedef long long ll;
#define ha putchar(' ')
#define he putchar('\n')
inline int read()
{
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9')
{
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = x * 10 + c - '0', c = getchar();
return x * f;
}
inline void write(int x)
{
if(x < 0)
{
putchar('-');
x = -x;
}
if(x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
const int _ = 1010, M = 2e5 + 10;
int n, m, rt, u[M], v[M], flg[_];
bool f1[_][_], f2[_][_];
bitset<_> vis;
vector<int> d[_];
void dfs1(int u)
{
vis.set(u);
f1[rt][u] = 1;
for(int v : d[u])
if(!vis[v]) dfs1(v);
}
void dfs2(int u, int cxr, bool t)
{
if(t) flg[u] = cxr;
else f2[rt][u] = (flg[u] != cxr);
vis.set(u);
for(int v : d[u])
if(!vis[v]) dfs2(v, cxr, t);
}
signed main()
{
n = read(), m = read();
for(int i = 1; i <= m; ++i)
{
u[i] = read(), v[i] = read();
d[u[i]].push_back(v[i]);
}
for(int i = 1; i <= n; ++i)
{
vis.reset();
rt = i;
dfs1(i);
}
for(int i = 1; i <= n; ++i)
{
vis.reset(), vis.set(i);
memset(flg, 0, sizeof flg);
int nw = d[i].size();
rt = i;
for(int j = 0; j < nw; ++j)
if(!vis[d[i][j]]) dfs2(d[i][j], j + 1, 1);
vis.reset(), vis.set(i);
for(int j = nw - 1; j >= 0; --j)
if(!vis[d[i][j]]) dfs2(d[i][j], j + 1, 0);
}
// for(int i = 1; i <= n; ++i)
// {
// for(int j = 1; j <= n; ++j) cout << f1[i][j] << " ";
// cout << "\n";
// }
// cout << "\n";
for(int i = 1; i <= n; ++i)
{
for(int j = 1; j <= n; ++j) cout << f2[i][j] << " ";
cout << "\n";
}
for(int i = 1; i <= m; ++i)
puts(f1[v[i]][u[i]] ^ f2[u[i]][v[i]] ? "diff" : "same");
return 0;
}
边栏推荐
- 域名抢注“卷”到了表情包?ENS逆势上涨的新推力
- 判断链表是否有环
- LeetCode二叉树系列——199二叉树的右视图
- The way of programmers' cultivation: do one's own responsibilities, be clear in reality - lead to the highest realm of pragmatism
- [VMware virtual machine installation mysql5.7 tutorial]
- 数据中台建设(五):打破企业数据孤岛和提取数据价值
- libudev 使用说明书
- Smart pointer implementation conjecture
- js人均寿命和GDP散点图统计样式
- 一本通循环结构的程序设计题解(2)
猜你喜欢
随机推荐
AT4108 [ARC094D] Normalization
学习笔记——七周成为数据分析师《第二周:业务》:业务分析指标
Synology system installation related file sharing
第十五天笔记
正确处理页面控制器woopagecontroller.php,当提交表单时是否跳转正确的页面
What are the hard-core upgrades and applications that cannot be missed in Greenplum 6.0?
R语言ggpubr包的ggboxplot函数可视化分组箱图、自定义移除可视化图像的特定对象(移除可视化图像轴坐标轴的刻度线标签文本、both x and y axis ticks labels)
jsArray数组复制方法性能测试2207300823
数据中台建设(五):打破企业数据孤岛和提取数据价值
BUUCTF刷题十一道(06)
Eleven BUUCTF questions (06)
群晖系统安装相关文件分享
R语言时间序列数据算术运算:使用log函数将时间序列数据的数值对数化(平方、开平方、指数化等函数类似使用)
shell脚本流程控制语句
深度操作系统DeepinOS安装步骤和MySQL安装测试
ARC115F Migration
666666
leetcode207.课程表(判断有向图是否有环)
pytorch学习记录(五):卷积神经网络的实现
无代码开发平台应用可见权限设置入门教程









