QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#186877#5160. Kebab PizzaForever_Young#WA 2ms12544kbC++141.2kb2023-09-24 13:00:582023-09-24 13:00:59

Judging History

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

  • [2023-09-24 13:00:59]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:12544kb
  • [2023-09-24 13:00:58]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,k,a[100010][2],inc[100010],cir,seq,one[100010],vis[100010];
set<int> s[100010];
vector<int> edge[100010];
int dfs(int x,int y){
	int res=0;
	vis[x]=1;
	for (int i=0;i<edge[x].size();i++)
	if (edge[x][i]!=y){
		if (vis[edge[x][i]]) res=1;
		else res|=dfs(edge[x][i],x);
	}
	return res;
}
int main(){
	scanf("%d%d",&n,&k);
	for (int i=0;i<n;i++){
		scanf("%d%d",&a[i][0],&a[i][1]);
		s[a[i][0]].insert(a[i][1]);
		s[a[i][1]].insert(a[i][0]);
	}
	//short
	for (int i=1;i<=k;i++)
	if (s[i].size()<=1) one[i]=1;
	for (int i=1;i<=k;i++)
	if (one[i]&&!s[i].empty()){
		int tmp=*s[i].begin();
		if (s[tmp].size()==1) seq=1;
		s[tmp].erase(i);
	}
	//long
	for (int i=1;i<=k;i++)
	if (!one[i]){
		s[i].erase(i);
		if (s[i].size()==0) seq=1;
		else if (s[i].size()>2){
			printf("impossible\n");
			return 0;
		}
		else{
			for (set<int>::iterator it=s[i].begin();it!=s[i].end();++it)
				edge[i].push_back(*it);
		}
	}
	for (int i=1;i<=k;i++)
	if (!vis[i]&&!one[i]){
		if (dfs(i,0)) cir=1;
		else seq=1;
	}
	if (cir==1&&seq==0) printf("possible\n");
	else if (cir==0) printf("possible\n");
	else printf("impossible\n");
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

possible

result:

ok single line: 'possible'

Test #2:

score: 0
Accepted
time: 2ms
memory: 11116kb

input:

5 5
1 3
1 5
2 3
2 5
3 4

output:

possible

result:

ok single line: 'possible'

Test #3:

score: 0
Accepted
time: 2ms
memory: 12544kb

input:

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

output:

impossible

result:

ok single line: 'impossible'

Test #4:

score: 0
Accepted
time: 0ms
memory: 11428kb

input:

8 4
1 1
1 2
2 1
2 2
3 3
3 4
4 3
4 4

output:

possible

result:

ok single line: 'possible'

Test #5:

score: 0
Accepted
time: 2ms
memory: 12160kb

input:

4 4
1 2
2 1
3 4
4 3

output:

possible

result:

ok single line: 'possible'

Test #6:

score: 0
Accepted
time: 2ms
memory: 12288kb

input:

5 4
1 1
1 4
2 2
2 4
3 4

output:

possible

result:

ok single line: 'possible'

Test #7:

score: 0
Accepted
time: 2ms
memory: 12008kb

input:

6 4
1 1
1 4
2 2
2 4
3 3
3 4

output:

impossible

result:

ok single line: 'impossible'

Test #8:

score: 0
Accepted
time: 0ms
memory: 11700kb

input:

4 5
1 2
3 4
4 5
5 3

output:

impossible

result:

ok single line: 'impossible'

Test #9:

score: 0
Accepted
time: 2ms
memory: 10880kb

input:

4 4
1 1
2 3
3 4
4 2

output:

impossible

result:

ok single line: 'impossible'

Test #10:

score: 0
Accepted
time: 2ms
memory: 11556kb

input:

3 4
1 2
2 3
3 1

output:

possible

result:

ok single line: 'possible'

Test #11:

score: 0
Accepted
time: 0ms
memory: 11748kb

input:

4 3
1 2
2 3
3 1
1 2

output:

possible

result:

ok single line: 'possible'

Test #12:

score: 0
Accepted
time: 0ms
memory: 11968kb

input:

5 4
1 2
2 3
3 1
1 4
4 4

output:

impossible

result:

ok single line: 'impossible'

Test #13:

score: 0
Accepted
time: 0ms
memory: 11628kb

input:

4 3
1 2
2 3
3 1
1 1

output:

possible

result:

ok single line: 'possible'

Test #14:

score: -100
Wrong Answer
time: 2ms
memory: 12528kb

input:

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

output:

possible

result:

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