QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#209395#5160. Kebab Pizza275307894aWA 8ms52832kbC++141.5kb2023-10-10 14:51:332023-10-10 14:51:33

Judging History

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

  • [2023-10-10 14:51:33]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:52832kb
  • [2023-10-10 14:51:33]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=1e6+5,M=N*4,K=600+5,mod=998244353,Mod=mod-1;const db eps=1e-6;const ll INF=1e15+7;mt19937 rnd(263082);
int fa[N],n,m,x,y;vector<int> S[N],G[N];
int GF(int x){return fa[x]^x?fa[x]=GF(fa[x]):x;}
void Solve(){
	int i,j;scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++) {
		scanf("%d%d",&x,&y);S[x].emplace_back(y);if(x^y) S[y].emplace_back(x);
	}
	vector<pii> e;
	for(i=1;i<=n;i++){
		vector<int> g;
		for(int j:S[i]) if(S[j].size()>1&&i^j) g.emplace_back(j),e.emplace_back(min(i,j),max(i,j));
		if(g.size()>2){puts("impossible");return;}
	}
	sort(e.begin(),e.end());e.erase(unique(e.begin(),e.end()),e.end());
	iota(fa+1,fa+n+1,1);int flag=0;
	for(auto i:e){
		int x=GF(i.fi),y=GF(i.se);
		if(x^y) fa[x]=y;
		else flag++;
	}
	if(!flag){puts("possible");return;}
	if(flag>=2){puts("impossible");return;}
	for(i=1;i<=n;i++) if(G[i].size()==1) flag=0;
	for(i=1;i<=n;i++) if(S[i].size()==1&&S[S[i][0]].size()==1) flag=0;
	puts(flag?"possible":"impossible");
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 51436kb

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: 4ms
memory: 51692kb

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: 8ms
memory: 52832kb

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

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: 4ms
memory: 51244kb

input:

4 4
1 2
2 1
3 4
4 3

output:

possible

result:

ok single line: 'possible'

Test #6:

score: 0
Accepted
time: 4ms
memory: 51968kb

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: 8ms
memory: 52192kb

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: 4ms
memory: 51264kb

input:

4 5
1 2
3 4
4 5
5 3

output:

impossible

result:

ok single line: 'impossible'

Test #9:

score: 0
Accepted
time: 8ms
memory: 51728kb

input:

4 4
1 1
2 3
3 4
4 2

output:

impossible

result:

ok single line: 'impossible'

Test #10:

score: 0
Accepted
time: 4ms
memory: 52740kb

input:

3 4
1 2
2 3
3 1

output:

possible

result:

ok single line: 'possible'

Test #11:

score: -100
Wrong Answer
time: 4ms
memory: 52368kb

input:

4 3
1 2
2 3
3 1
1 2

output:

impossible

result:

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