QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#432594#8686. Zoo ManagementORzyzROWA 0ms33692kbC++141.9kb2024-06-07 12:57:222024-06-07 12:57:23

Judging History

你现在查看的是最新测评结果

  • [2024-06-07 12:57:23]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:33692kb
  • [2024-06-07 12:57:22]
  • 提交

answer

#include<bits/stdc++.h>
#define GG {puts("impossible");return 0;}
using namespace std;
typedef long long LL;
const LL p1=1000000007,p2=1000000009,bs=19260817,N=1000005;
LL b1[N],b2[N],h1[N],h2[N];
LL n,m,hd[N],nx[N],to[N],is[N],dfc,cn=1,low[N],dfn[N],vs[N],a[N],b[N],vi[N],ge,vc,ec;
void add(LL x,LL y){nx[++cn]=hd[x];hd[x]=cn;to[cn]=y;}
vector<LL>U,V,U1,V1;
void dfs(LL x){
	low[x]=dfn[x]=++dfc;
	for(LL i=hd[x],y;i;i=nx[i])
	if(!vs[i]){
		vs[i]=vs[i^1]=1;
		if(!dfn[y=to[i]]){
			dfs(y);low[x]=min(low[x],low[y]);
			if(low[y]==dfn[y])is[i]=is[i^1]=1;
		}else low[x]=min(low[x],dfn[y]);
	}
}
void df(LL x,LL fa){
	low[x]=dfn[x]=++dfc;vi[x]=1;++vc;int cd=0;U.push_back(a[x]);V.push_back(b[x]);
	for(LL i=hd[x],y;i;i=nx[i])if(!is[i]){
		++ec;
		if(!dfn[y=to[i]]){
			df(y,x),low[x]=min(low[x],low[y]),++cd;
			if(fa&&low[y]>=dfn[x])ge=1;
		}
		else low[x]=min(low[x],dfn[y]);
	}
	if(!fa&&cd>1)ge=1;
}
int main(){
	ios::sync_with_stdio(false);cin>>n>>m;
	b1[0]=b2[0]=1;for(LL i=1;i<=n;++i)b1[i]=b1[i-1]*bs%p1,b2[i]=b2[i-1]*bs%p2;
	for(LL i=1;i<=n;++i)cin>>a[i]>>b[i];
	for(LL x,y;m--;){cin>>x>>y;add(x,y);add(y,x);}
	for(LL i=1;i<=n;++i)if(!dfn[i])dfs(i);
	memset(low,0,sizeof(low));memset(dfn,0,sizeof(dfn)); 
	for(LL i=1;i<=n;++i)if(!vi[i]){
		LL fl=0;for(LL j=hd[i];j;j=nx[j])if(!is[j]){fl=1;break;}
		if(!fl)if(a[i]!=b[i])GG else continue;
		ge=vc=ec=0;U.clear();V.clear();df(i,0);ec/=2;
		U1=U;V1=V;sort(U1.begin(),U1.end());sort(V1.begin(),V1.end());
		if(U1!=V1)GG
		if(ge)continue;
		if(ec>vc+1)continue;
		if(ec==vc){
			for(LL i=1;i<=vc;++i)h1[i]=(h1[i-1]*bs+U[i-1])%p1,h2[i]=(h2[i-1]*bs+U[i-1])%p2;
			LL H1=0,H2=0,fl=0;
			for(LL i=1;i<=vc;++i)H1=(H1*bs+V[i-1])%p1,H2=(H2*bs+V[i-1])%p2;
			for(LL i=1;i<=vc;++i)if(((h1[vc]-h1[i]*b1[vc-i]%p1+p1)*b1[i]+h1[i])%p1==H1)
			if(((h2[vc]-h2[i]*b2[vc-i]%p2+p2)*b2[i]+h2[i])%p2==H2){fl=1;break;}
			if(!fl)GG else continue;
		}
	}
	puts("possible");
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 33692kb

input:

6 7
1 1
2 2
3 3
1 2
2 3
3 1
1 2
2 3
1 3
3 4
4 5
5 6
4 6

output:

possible

result:

ok single line: 'possible'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 33620kb

input:

5 6
10 10
20 20
30 30
40 50
50 40
1 2
2 3
1 3
3 4
3 5
4 5

output:

possible

result:

wrong answer 1st lines differ - expected: 'impossible', found: 'possible'