当前位置:网站首页>[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;
}
边栏推荐
- PyQt5快速开发与实战 8.6 设置样式
- “封号斗罗” 程序员修炼之道:通向务实的最高境界
- (HR面试)最常见的面试问题和技巧性答复
- SQL 26 calculation under 25 years of age or older and the number of users
- 重保特辑|筑牢第一道防线,云防火墙攻防演练最佳实践
- matlab画图,仅显示部分图例
- Synology system installation related file sharing
- 深度操作系统DeepinOS安装步骤和MySQL安装测试
- 戴墨镜的卡通太阳SVG动画js特效
- Anaconda\Scripts\pip-script.py is not present ? 解决方案
猜你喜欢

LeetCode二叉树系列——199二叉树的右视图

05 | login background: based on the password login mode (below)

The path to uniting the programmer: "titles bucket" to the highest state of pragmatic

数据中台建设(五):打破企业数据孤岛和提取数据价值

pytorch学习记录(六):循环神经网络 RNN & LSTM

无代码开发平台全部应用设置入门教程

Raja Koduri澄清Arc GPU跳票传闻 AXG年底前新推四条产品线

学习笔记——七周成为数据分析师《第一周:数据分析思维》

【微信小程序】一文带你搞懂小程序的页面配置和网络数据请求

【ROS进阶篇】第十一讲 基于Gazebo和Rviz的机器人联合仿真(运动控制与传感器)
随机推荐
正确处理页面控制器woopagecontroller.php,当提交表单时是否跳转正确的页面
TaskDispatcher source code parsing
Anaconda\Scripts\pip-script.py is not present ? 解决方案
(HR面试)最常见的面试问题和技巧性答复
odoo--qweb模板介绍(一)
58. 最后一个单词的长度
cpu/CS and IP
05 | login background: based on the password login mode (below)
程序员修炼之道:务以己任,实则明心——通向务实的最高境界
[ARC092D] Two Faced Edges
[PostgreSQL] - explain SQL analysis introduction
SQL 改写系列七:谓词移动
20220729 证券、金融
Study Notes - Becoming a Data Analyst in Seven Weeks "Week 2: Business": Business Analysis Metrics
strlen跟sizeof区别
Composer安装方式
R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化分组箱图、使用ggpar函数改变图形化参数(ylim、修改可视化图像y轴坐标轴数值范围)
[论文翻译] Unpaired Image-To-Image Translation Using Cycle-Consistent Adversarial Networks
libudev 使用说明书
pytorch学习记录(五):卷积神经网络的实现