QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#102674#5160. Kebab Pizzaw4p3r#WA 2ms3504kbC++201.7kb2023-05-03 15:52:032023-05-03 15:52:23

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-03 15:52:23]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3504kb
  • [2023-05-03 15:52:03]
  • 提交

answer

#include<bits/stdc++.h>
#define N 100005
using namespace std;
int n,m;
int in[N];
struct node{
	int x,y;
}Q[N],E[N];
inline bool cmp(node a,node b){
	return a.x==b.x?a.y<b.y:a.x<b.x;
}
inline void Rd(int &res){
	char c;res=0;
	while(c=getchar(),c<48);
	do res=(res<<3)+(res<<1)+(c^48);
	while(c=getchar(),c>47);
	return;
}
bool mark[N],vis[N];
inline bool add_edge(int a,int b){
	if(E[a].x==-1)E[a].x=b;
	else if(E[a].y==-1)E[a].y=b;
	else return false;
	return true;
}
int dfs(int x,int f){
	if(x==-1)return 2;
	if(vis[x])return 1;
	vis[x]=1;
	int nxt=Q[x].x;
	if(Q[x].x==f)nxt=Q[x].y;
	return dfs(nxt,x);
}
inline bool check(){
	for(int i=1;i<=m;i++)E[i].x=-1,E[i].y=-1;
	for(int i=1;i<=n;i++)if(Q[i].x==Q[i].y)mark[Q[i].x]=1;
	for(int i=1;i<=n;i++){
		if(Q[i].x==Q[i].y)continue;
		if(!add_edge(Q[i].x,Q[i].y))return false;
		if(!add_edge(Q[i].y,Q[i].x))return false;
	}
	int key=0;
	for(int i=1;i<=m;i++)if(!vis[i]){
		if(E[i].x==-1)continue;
		if(key==1)return false;
		int o=dfs(E[i].x,-2);
		if(o==1){
			if(key)return false;
			key=1;
		}
		else{
			key=2;
			dfs(E[i].y,-2);
		}
	}
	if(key!=1)return true;
	for(int i=1;i<=m;i++)if(mark[i]&&!vis[i])return false;
	return true;
}
int main(){
	Rd(n);Rd(m);
	for(int i=1;i<=n;i++){
		Rd(Q[i].x);Rd(Q[i].y);
		if(Q[i].x>Q[i].y)swap(Q[i].x,Q[i].y);
	}
	
	sort(Q+1,Q+n+1,cmp);
	int h=1;
	for(int i=2;i<=n;i++)if(Q[i].x!=Q[h].x||Q[i].y!=Q[h].y)Q[++h]=Q[i];
	n=h;
	for(int i=1;i<=n;i++){
		in[Q[i].x]++;
		if(Q[i].x!=Q[i].y)in[Q[i].y]++;
	}
	h=0;
	for(int i=1;i<=n;i++)if((in[Q[i].x]>1&&in[Q[i].y]>1)||Q[i].x==Q[i].y)Q[++h]=Q[i];
	n=h;
	if(check())puts("possible");
	else puts("impossible");
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3504kb

input:

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

output:

impossible

result:

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