# Bzoj1823 [jsoi2010]满汉全席

Posted by yjjr's blog on February 6, 2018

# 题目

Description

3 4

m3 h1

m1 m2

h1 h3

h3 m2

2 4

h1 m2

m2 m1

h1 h2

m1 h2

Sample Output GOOD

HINT

Source

JSOI2010第二轮Contest2

# code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
{
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int maxn=1e6+6;
int Que,n,m,cnt=1,ind,scc,top,last[maxn],dfn[maxn],low[maxn],que[maxn],belong[maxn];
bool inq[maxn];
struct edge{int to,next;}e[maxn<<2];
int get()
{
int x;char ch=getchar();
while(ch!='m'&&ch!='h')ch=getchar();
return x;
}

void insert(int u,int v){e[++cnt]=(edge){v,last[u]};last[u]=cnt;}
void tarjan(int x){
low[x]=dfn[x]=++ind;
inq[x]=1;que[++top]=x;
reg(x)
if(!dfn[e[i].to]){
tarjan(e[i].to);
low[x]=min(low[x],low[e[i].to]);
}
else if(inq[e[i].to])low[x]=min(low[x],dfn[e[i].to]);
if(low[x]==dfn[x]){
int now=0;scc++;
while(now!=x){
now=que[top--];
belong[now]=scc;
inq[now]=0;
}
}
}
int main()
{
while(Que--){
top=ind=cnt=scc=0;
rep(i,1,n*2)last[i]=dfn[i]=0;
rep(i,1,m){
int x=get(),y=get(),xp,yp;
if(x%2==0)xp=x--;else xp=x++;
if(y%2==0)yp=y--;else yp=y++;
insert(xp,y);insert(yp,x);
}
bool flag=0;
rep(i,1,2*n)
if(!dfn[i])tarjan(i);
rep(i,1,n)
if(belong[2*i]==belong[2*i-1]){