BZOJ 2140 稳定婚姻
来源:互联网 发布:朗读英语的软件 编辑:程序博客网 时间:2024/05/18 02:54
和稳定婚姻、匹配没有任何关系啊有木有。。。
大概就是把婚外情的家庭编号用单向边连接(男方编号指向女方编号),如果这些编号存在自环,则其家庭之间已经出现满足出轨条件的状况了。
#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<string>#include<algorithm>#include<map> using namespace std; const int maxn=4005;const int maxm=20005; map<string,int>num; struct edge{ int next,to;}e[maxm]; int n,m,cnt,scccnt,dfs_clock,top;int head[maxn],dfn[maxn],low[maxn];int belong[maxn],sccnum[maxn],stack[maxn];bool vst[maxn]; void insert(int a,int b){ e[++cnt].to=b;e[cnt].next=head[a];head[a]=cnt;}void tarjan(int x){ dfn[x]=low[x]=++dfs_clock; stack[++top]=x; vst[x]=true; for(int i=head[x];i;i=e[i].next) { int y=e[i].to; if(!dfn[y]) tarjan(y),low[x]=min(low[x],low[y]); else if(vst[y]) low[x]=min(low[x],dfn[y]); } if(dfn[x]==low[x]) { int now=-1; ++scccnt; while(now!=x) { now=stack[top--]; belong[now]=scccnt; vst[now]=false; sccnum[scccnt]++; } }}int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) { string st; cin>>st; num[st]=i; cin>>st; num[st]=n+i; } scanf("%d",&m); for(int i=1;i<=m;i++) { string st1,st2; cin>>st1; cin>>st2; insert(num[st1],num[st2]-n); } for(int i=1;i<=n;i++) if(!dfn[i])tarjan(i); for(int i=1;i<=n;i++) printf(sccnum[belong[i]]>1?"Unsafe\n":"Safe\n"); return 0;}
阅读全文
0 0
- 【BZOJ】2140 稳定婚姻
- bzoj 2140: 稳定婚姻
- 【BZOJ】2140: 稳定婚姻
- BZOJ 2140 稳定婚姻
- BZOJ 2140: 稳定婚姻
- BZOJ 2140 稳定婚姻
- BZOJ 2140 稳定婚姻
- BZOJ 2140 稳定婚姻
- BZOJ 2140: 稳定婚姻 tarjan
- BZOJ 2140 稳定婚姻题解
- [bzoj-2140]稳定婚姻 题解
- bzoj 2140: 稳定婚姻 强连通分量
- BZOJ 2140 稳定婚姻 (Tarjan)
- BZOJ P2140稳定婚姻
- BZOJ 2140 稳定婚姻 Tarjan 强连通分量
- [BZOJ 2140] 稳定婚姻 Tarjan求强连通分量
- [二分图完美匹配必要边 强连通分量] BZOJ 2140 稳定婚姻
- 稳定婚姻
- windows中安装tomcat
- Linux磁盘分区,格式化,检查及挂载
- 指针的一个问题思考
- 关于JAVA中RSA加签解签,私钥加密公钥解密和公钥加密私钥解密代码步骤
- 指针学习
- BZOJ 2140 稳定婚姻
- [LeetCode] 561.Array Partition I 备忘
- lintcode 转换字符串到整数
- C 指针操作说明上
- PHP进阶(第九弹:日期时间函数)
- LeetCode-Q22-Generate Paretheses
- APNG在QT中的使用(一)
- Maven学习笔记——新建maven web项目缺失文件夹的问题解决
- TabLayout && ViewPager _布局文件