Party

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5558    Accepted Submission(s): 1809

Problem Description
有n对夫妻被邀请参加一个聚会,因为场地的问题,每对夫妻中只有1人可以列席。在2n 个人中,某些人之间有着很大的矛盾(当然夫妻之间是没有矛盾的),有矛盾的2个人是不会同时出现在聚会上的。有没有可能会有n 个人同时列席?
 
Input
n: 表示有n对夫妻被邀请 (n<= 1000)
m: 表示有m 对矛盾关系 ( m < (n - 1) * (n -1))

在接下来的m行中,每行会有4个数字,分别是 A1,A2,C1,C2
A1,A2分别表示是夫妻的编号
C1,C2 表示是妻子还是丈夫 ,0表示妻子 ,1是丈夫
夫妻编号从 0 到 n -1

 
Output
如果存在一种情况 则输出YES
否则输出 NO
 
Sample Input
2
1
0 1 1 1
 
Sample Output
YES
  模板题。
 #include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn=;
int n,m;
int cnt,fir[maxn],nxt[maxn*],to[maxn*];
void addedge(int a,int b){
nxt[++cnt]=fir[a];
fir[a]=cnt;
to[cnt]=b;
}
int scc[maxn],scnt;
int ID[maxn],low[maxn],tot;
int st[maxn],top; void Tarjan(int x){
ID[x]=low[x]=++tot;st[++top]=x;
for(int i=fir[x];i;i=nxt[i]){
if(ID[to[i]]){
if(!scc[to[i]])
low[x]=min(low[x],ID[to[i]]);
}
else{
Tarjan(to[i]);
low[x]=min(low[x],low[to[i]]);
}
}
if(low[x]==ID[x]){
++scnt;
while(true){
int y=st[top--];
scc[y]=scnt;
if(x==y)break;
}
}
}
bool Solve(){
for(int i=;i<*n;i++)
if(!ID[i])Tarjan(i); for(int i=;i<n;i++)
if(scc[i*]==scc[i*+])
return false;
return true;
} void Init(){
memset(fir,,sizeof(fir));
memset(scc,,sizeof(scc));
memset(ID,,sizeof(ID));
cnt=;tot=;scnt=;
} int main(){
while(scanf("%d%d",&n,&m)!=EOF){
Init();
while(m--){
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
a=a*+c;b=b*+d;
addedge(a,b^);addedge(b,a^);
}
if(Solve())
printf("YES\n");
else
printf("NO\n");
}
return ;
}

最新文章

  1. 自定义从Azure下载回来的远程桌面连接(.rdp)文件,使其提供更多丰富功能
  2. MATLAB数字图像处理基础
  3. Sprint(第十二天11.25)
  4. C#知识体系(一) --- 常用的LInq 与lambda表达式
  5. Hadoop官方文档翻译——YARN Architecture(2.7.3)
  6. js中的换算小技巧
  7. 40页PPT勾画“互联网颠覆性思维”----诠释互联网思维
  8. 学习BigDecimal用法
  9. VS2013的virtualpath在当前应用程序根的外部
  10. 5. Longest Palindromic Substring -- 最长回文字串
  11. numpy常用函数
  12. 关于mybatis组合查询的分析
  13. linux设置语言编码
  14. Android JSON 解析库的使用 - Gson 和 fast-json
  15. Acdream1157---Segments (CDQ分治)
  16. SQL Server 备份维护计划
  17. html5后台界面
  18. C++写#pragma warning(disable 4786)的作用
  19. 【python】使用unix管道pipe处理stdout实时数据
  20. 【SoftwareTesting】Homework1

热门文章

  1. LDAP7卸载
  2. spring 定时任务的 执行时间设置规则
  3. c读mysql产生乱码问题
  4. sql常用的日期函数与应用
  5. wpf 调用线程必须为sta 因为许多ui组件都需要
  6. ASP.NET Excel数据导入数据库
  7. oracle模糊查询效率可这样提高
  8. Deep Learning学习随记(二)Vectorized、PCA和Whitening
  9. iOS中JavaScript和OC交互
  10. JqGrid自定义toolbar