HDU 1824 Let's go home (2-SAT判定)
Let's go home
Time Limit: 10000/1000 MS (Java/Others) Memory
Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1616 Accepted Submission(s): 661
—— 余光中
集训是辛苦的。道路是坎坷的,歇息还是必须的。经过一段时间的训练,lcy决定让大家回家放松一下,可是训练还是得照常进行,lcy想出了例如以下回家规定,每个队(三人一队)或者队长留下或者其余两名队员同一时候留下;每一对队员,假设队员A留下,则队员B必须回家歇息下,或者B留下,A回家。因为今年集训队人数突破往年同期最高记录,管理难度相当大。lcy也不知道自己的决定是否可行,所以这个难题就交给你了,呵呵,优点嘛~。免费**漂流一日。
接下来有T行,每行三个整数,表示一个队的队员编号,第一个队员就是该队队长。
然后有M行,每行两个整数,表示一对队员的编号。
每一个队员仅仅属于一个队。
队员编号从0開始。
1 2
0 1 2
0 1
1 2 2 4
0 1 2
3 4 5
0 3
0 4
1 3
1 4
yes
no
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
#define LL long long
using namespace std;
const int MAXN = 20010;
vector<int>G[MAXN];
int pre[MAXN], lowlink[MAXN], sccno[MAXN], dfs_clock, scc_cnt;
stack<int> s;
void dfs(int u)
{
pre[u] = lowlink[u] = ++dfs_clock;
s.push(u); int sz = G[u].size();
for(int i=0;i<sz;i++)
{
int v = G[u][i];
if(!pre[v])
{
dfs(v);
lowlink[u] = min(lowlink[u], lowlink[v]);
}
else if(!sccno[v])
{
lowlink[u] = min(lowlink[u], pre[v]);
}
}
if(lowlink[u] == pre[u])
{
scc_cnt++;
for(;;)
{
int x = s.top(); s.pop();
sccno[x] = scc_cnt;
if(x == u) break;
}
}
}
void find_scc(int n)
{
dfs_clock = scc_cnt = 0;
memset(sccno, 0, sizeof(sccno));
memset(pre, 0, sizeof(pre));
for(int i=1;i<=n;i++) if(!pre[i])
dfs(i);
}
int N, M, T;
int main()
{
while(scanf("%d%d", &T, &M)!=EOF)
{
int x, y, z;
N = 3 * T;
for(int i=0;i<=2*N;i++) G[i].clear();
for(int i=1;i<=T;i++)
{
scanf("%d%d%d", &x, &y, &z);
x++; y++; z++;
G[x+N].push_back(y);
G[x+N].push_back(z);
G[y+N].push_back(x);
G[z+N].push_back(x);
}
for(int i=1;i<=M;i++)
{
scanf("%d%d", &x, &y);
x++; y++;
G[x].push_back(y + N);
G[y].push_back(x + N);
}
find_scc(2 * N);
int flag = 1;
for(int i=1;i<=N;i++)
{
if(sccno[i] == sccno[i + N])
{
flag = 0;
break;
}
}
if(flag) puts("yes");
else puts("no");
}
return 0;
}
HDU 1824 Let's go home (2-SAT判定)的更多相关文章
- HDU 3062 && HDU 1824 && POJ 3678 && BZOJ 1997 2-SAT
一条边<u,v>表示u选那么v一定被选. #include <iostream> #include <cstring> #include <cstdio> ...
- HDU 1824 Let's go home(2-SAT+Tarjan)
Let's go home Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu 3966 Aragorn's Story(树链剖分+树状数组)
pid=3966" target="_blank" style="">题目链接:hdu 3966 Aragorn's Story 题目大意:给定 ...
- HDU 3966 Aragorn's Story(树链剖分)
HDU Aragorn's Story 题目链接 树抛入门裸题,这题是区间改动单点查询,于是套树状数组就OK了 代码: #include <cstdio> #include <cst ...
- hdu 5282 Senior's String 两次dp
题链:http://acm.hdu.edu.cn/showproblem.php?pid=5282 Senior's String Time Limit: 2000/1000 MS (Java/Oth ...
- HDU 3177 Crixalis's Equipment(贪婪)
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=3177 Problem Description Crixalis - Sand King used t ...
- HDU - 5186 - zhx's submissions (精密塔尔苏斯)
zhx's submissions Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- HDU 2120 Ice_cream's world I(并检查集合)
职务地址:HDU 2120 这题尽管字数不多,但就是看不懂. . 意思是求最多有多少个被墙围起来的区域.显然就是求环的个数.然后用并查集求环个数就能够了. 代码例如以下: #include <i ...
- HDU 3729 I'm Telling the Truth(二部图最大匹配+结果输出)
职务地址:HDU 3729 二分图最大匹配+按字典序输出结果. 仅仅要从数字大的開始匹配就能够保证字典序最大了.群里有人问. . 就顺手写了这题. . 代码例如以下: #include <ios ...
随机推荐
- 01Ping程序的设计
1.Ping程序设计具体设计任务 1.1 实验目的 PING程序是我们使用的比较多的用于测试网络连通性的程序.PING程序基于ICMP,使用ICMP的回送请求和回送应答来工作.由计算机网络课程知道,I ...
- 我的Python分析成长之路1
Python是什么? ...
- pwnable.kr cmd1之write up
看一下源代码: #include <stdio.h> #include <string.h> int filter(char* cmd){ ; r += strstr(cmd, ...
- HDU 1257 最少拦截系统(最长上升子序列)
题意: 给定n个数, 然后要求看看有多少对不上升子序列. 分析: 求出最长上升子序列, 那么整个序列中LIS外的数都会在前面找到一个比自己大的数, 所以不上升子序列最多有最长上升子序列个数个. 关于求 ...
- struts2接受请求参数
https://blog.csdn.net/y249839817/article/details/77702745 https://blog.csdn.net/nthack5730/article/d ...
- 学渣乱搞系列之扩展KMP的那点事
扩展KMP牵涉了一些相对运动的姿势,比较费解!本学渣看了一天的扩展KMP,打算写点东西...本文看后,出现的后果本人一概不负责.毕竟我不是很会表达. 扩展KMP是搞什么灰机的?本学渣所知道的扩展KMP ...
- CodeForces - 356A Knight Tournament
http://codeforces.com/problemset/problem/356/A 首先理解题意 每次给出l 和r 在l - r之间还有资格的选手中得出一个胜者 暴力思路: 首先维护还有资 ...
- 关闭spring整合kafka时,消费者一直打印kafka日志
在log4j.properties中添加如下代码 log4j.logger.org.apache.kafka.common.metrics.Metrics=OFF log4j.logger.org.a ...
- ESI+varnish页面片段缓存
对于片段缓存,业界有成熟的解决方案,还有一个所谓的W3C标准:ESI(Edge Side Include) . ESI本身没有什么,只是一个XML的标签集合.ESI和SSI(Server Side I ...
- linux 报错:E: Package 'libmemcached' has no installation candidate
linux 报错:E: Package 'libmemcached' has no installation candidate 网上查资料说是软件安装源没有这个软件,需要添加软件源. 1.备份源列表 ...