当前位置:网站首页>[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;
}
边栏推荐
- R语言使用方差分析ANOVA比较回归模型的差异、anova函数比较两个模型并报告它们是否存在显著差异(两个模型的数据相同,一个模型使用的预测特征包含另外一个模型的特征)
- shell脚本流程控制语句
- PyQt5快速开发与实战 8.6 设置样式
- CMake库搜索函数居然不搜索LD_LIBRARY_PATH
- 学习笔记——七周成为数据分析师《第二周:业务》:业务分析指标
- ARC115F Migration
- odoo--qweb模板介绍(一)
- R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化分组箱图、使用ggpar函数改变图形化参数(ylim、修改可视化图像y轴坐标轴数值范围)
- pytorch学习记录(六):循环神经网络 RNN & LSTM
- [Go]四、模块和包、流程控制、结构体
猜你喜欢
随机推荐
js背景切换时钟js特效代码
阿里 P7 到底是怎样的水平?
TaskDispatcher source code parsing
Scala基础:数组(Array)、映射(Map)、元组(Tuple)、集合(List)
leetcode207.课程表(判断有向图是否有环)
libudev 使用说明书
Hand tearing read-write lock performance test
【自校正控制】自校正PID
BUUCTF刷题十一道(06)
jsArray array copy method performance test 2207300823
R语言时间序列数据算术运算:使用log函数将时间序列数据的数值对数化(平方、开平方、指数化等函数类似使用)
05 | 后台登录:基于账号密码的登录方式(下)
jsArray array copy method performance test 2207300040
剑指 Offer 05. 替换空格
[C# 循环跳转]-C# 中的 while/do-while/for/foreach 循环结构以及 break/continue 跳转语句
在 Scala 中读取整个文件
R语言ggplot2可视化:使用ggpubr包的ggmaplot函数可视化MA图(MA-plot)、设置label.select参数自定义在图中显示标签的基因类型(自定义显示的标签列表)
Study Notes - Becoming a Data Analyst in Seven Weeks "Week 2: Business": Business Analysis Metrics
DeFi 巨头进军 NFT 领域 用户怎么看?
05 | login background: based on the password login mode (below)









