QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#201754#5160. Kebab Pizzasalvator_noster#WA 0ms3776kbC++201.3kb2023-10-05 16:37:232023-10-05 16:37:23

Judging History

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

  • [2023-10-05 16:37:23]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3776kb
  • [2023-10-05 16:37:23]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int M=1e5+10;
typedef pair<int,int> pii;
pii piz[M];
int cnt[M],deg[M];
char loop;
int fath[M];

int Find(int x) {return x == fath[x] ? x : fath[x] = Find(fath[x]);}

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
    set <int> sss;
	for(int i=1;i<=n;++i){
		int a,b;
		scanf("%d%d",&a,&b);
        sss.insert(a); sss.insert(b);
		if(a>b)swap(a,b);
		piz[i]=make_pair(a,b);
	}
    for (int i = 1; i <= k; i ++) fath[i] = i;
	sort(piz+1,piz+n+1);
	n=unique(piz+1,piz+n+1)-piz-1;
	for(int i=1;i<=n;++i){
		auto [a,b]=piz[i];
		if(a==b){
            continue;
        }
		cnt[a]++,cnt[b]++;
	}
	for(int i=1;i<=n;++i){
		auto [a,b]=piz[i];
		if(a==b)continue;
		if(cnt[b]>=2)deg[a]++;
		if(cnt[a]>=2)deg[b]++;
	}
	for(int i=1;i<=k;++i){
		if(deg[i]>2){
			puts("impossible");
			return 0;
		}
	}
    for (int i = 1; i <= n; i ++) {
        auto [a,b] = piz[i];
        if (a == b) continue;
        a = Find(a); b = Find(b);
        if (a == b) {
            loop = 1;
        }
        fath[a] = b;
    }
    if (loop) {
        set <int> s;
        for (int i = 1; i <= k; i ++)
            if (sss.count(i)) s.insert(Find(i));
        if (s.size() != 1) {
            puts("impossible");
			return 0;
        }
    }
	puts("possible");
	return 0;
}

詳細信息

Test #1:

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

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

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

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

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

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

input:

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

output:

possible

result:

ok single line: 'possible'

Test #7:

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

input:

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

output:

possible

result:

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