当前位置:网站首页>[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;
}
边栏推荐
- curl 执行脚本时传递环境变量与参数
- 剑指 Offer 05. 替换空格
- Synology system installation related file sharing
- SQL 26 calculation under 25 years of age or older and the number of users
- BUUCTF刷题十一道(06)
- Current and voltage acquisition module DAM-6160
- 数据中台建设(五):打破企业数据孤岛和提取数据价值
- 一本通循环结构的程序设计第一章题解(1)
- Learning notes - 7 weeks as data analyst "in the first week: data analysis of thinking"
- Parallelized Quick Sort Ideas
猜你喜欢

How to display an Excel table in the body of an email?

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

jsArray array copy method performance test 2207300823

【高等数学】【7】二重积分

戴墨镜的卡通太阳SVG动画js特效

jsArray数组复制方法性能测试2207300823

TaskDispatcher源码解析

ML之PDP:基于FIFA 2018 Statistics(2018年俄罗斯世界杯足球赛)球队比赛之星分类预测数据集利用DT决策树&RF随机森林+PDP部分依赖图可视化实现模型可解释性之详细攻略

Markdown 1 - 图文音视频等

leetcode207.课程表(判断有向图是否有环)
随机推荐
OFDM 十六讲 3- OFDM Waveforms
【23考研】408代码题参考模板——链表
Eleven BUUCTF questions (06)
DeFi 巨头进军 NFT 领域 用户怎么看?
There is a risk of water ingress in the battery pack tray and there is a potential safety hazard. 52,928 Tang DMs are urgently recalled
“封号斗罗” 程序员修炼之道:通向务实的最高境界
创意loadingjs特效小点跳跃动画
cpu / CS 和 IP
电池包托盘有进水风险,存在安全隐患,紧急召回52928辆唐DM
Markdown 1 - 图文音视频等
正确处理页面控制器woopagecontroller.php,当提交表单时是否跳转正确的页面
无代码开发平台应用可见权限设置入门教程
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
CF1320E Treeland and Viruses
人社部公布“数据库运行管理员”成新职业,OceanBase参与制定职业标准
jsArray数组复制方法性能测试2207292307
R语言ggplot2可视化时间序列数据(默认时间中断部分前后自动连接起来)、创建时间分组、使用分面图(faceting)可视化时间序列数据
for循环的3个表达式执行顺序
UPC2022暑期个人训练赛第19场(B,P)
dolphinscheduler adds hana support