hdu就是会卡cin,,

另一种建模方式,把点i拆成i*2,i*2+1,有时候这样会比较简单

#include<bits/stdc++.h>
using namespace std;
#define N 4005
#define M 2000005
struct Edge{int to,nxt;}e[M<<];
int n,m,head[N],tot;
void add(int u,int v){
e[tot].to=v;e[tot].nxt=head[u];head[u]=tot++;
} int low[N],dfn[N],cnt,id[N],ind,stk[N],top,ins[N];
void tarjan(int x){
dfn[x]=low[x]=++ind;
stk[++top]=x;ins[x]=;
for(int i=head[x];i!=-;i=e[i].nxt){
int y=e[i].to;
if(!dfn[y]){
tarjan(y);
low[x]=min(low[x],low[y]);
}
else if(ins[y])
low[x]=min(low[x],low[y]);
}
if(dfn[x]==low[x]){
cnt++;int y;
do{
y=stk[top--];
ins[y]=;
id[y]=cnt;
}while(x!=y);
}
} void init(){
cnt=tot=top=ind=;
memset(head,-,sizeof head);
memset(dfn,,sizeof dfn);
memset(low,,sizeof low);
memset(id,,sizeof id);
}
int main(){
while(cin>>n>>m && n){
init();
for(int i=;i<m;i++){
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
a<<=,b<<=;
a+=c;b+=d;
add(a,b^),add(b,a^);
}
for(int i=;i<*n;i++)
if(!dfn[i])tarjan(i); int flag=;
for(int i=;i<n;i++)
if(id[i*]==id[i*+]){
puts("NO");
flag=;
break;
}
if(!flag)puts("YES");
}
}

最新文章

  1. 数据集偏斜 - class skew problem - 以SVM松弛变量为例
  2. MonjaDB —— 基于 Eclipse 的 MongoDB GUI 客户端工具(转载)
  3. JAVA SSM 示例代码
  4. PowerShell脚本自动设置安卓手机wifi代理
  5. JDBC操作步骤及数据库连接操作
  6. SQL Cookbook
  7. POSIX, Bash, GPL etc
  8. 数组的方法 Array.map();Array.every()和Array.some();数组的indexof();检测是否是数组isArray(obj);
  9. Python——目录操作
  10. Hibernate与 MyBatis的比较
  11. 【转载】jQuery插件开发精品教程,让你的jQuery提升一个台阶
  12. multipath 安装配置
  13. hdu 3535 AreYouBusy
  14. EasyUI - DataGrid 组建 - [ 组件加载和分页 ]
  15. DevExpress ASP.NET Core Controls 2019发展蓝图(No.1)
  16. springboot下载文件
  17. LeetCode: Largest Number 解题报告 以及Comparator, CompareTo 应用
  18. 今天看到的一些js的用法
  19. MariaDB&#160;Centos7&#160;下安装MariaDB
  20. Python3中 sys.argv的用法

热门文章

  1. AtCoder ABC 132E Hopscotch Addict
  2. iBATIS结果映射
  3. springboot整合thymeleaf手动渲染
  4. window下apache2.2配置多个tomcat使用不同二级域名,共用80端口
  5. 重写(Overriding)和重载(Overloading)
  6. vue-router 的重定向-redirect
  7. Android系统开发 编译系统签名的APP
  8. try install gitlab ce at docker ce
  9. [JZOJ6258] 【省选模拟8.9】轰炸
  10. sql语句之条件,分页,排序