QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#186871#5160. Kebab PizzaForever_Young#WA 3ms12724kbC++141.2kb2023-09-24 12:54:472023-09-24 12:54:47

Judging History

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

  • [2023-09-24 12:54:47]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:12724kb
  • [2023-09-24 12:54:47]
  • 提交

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");
}

详细

Test #1:

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

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: 0ms
memory: 11876kb

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: 12724kb

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: 2ms
memory: 10876kb

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: 12384kb

input:

4 4
1 2
2 1
3 4
4 3

output:

possible

result:

ok single line: 'possible'

Test #6:

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

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: 12272kb

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: 3ms
memory: 10852kb

input:

4 5
1 2
3 4
4 5
5 3

output:

impossible

result:

ok single line: 'impossible'

Test #9:

score: 0
Accepted
time: 3ms
memory: 11236kb

input:

4 4
1 1
2 3
3 4
4 2

output:

impossible

result:

ok single line: 'impossible'

Test #10:

score: -100
Wrong Answer
time: 3ms
memory: 11028kb

input:

3 4
1 2
2 3
3 1

output:

impossible

result:

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