QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#209386#5160. Kebab Pizza275307894aWA 13ms52688kbC++141.4kb2023-10-10 14:46:162023-10-10 14:46:17

Judging History

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

  • [2023-10-10 14:46:17]
  • 评测
  • 测评结果:WA
  • 用时:13ms
  • 内存:52688kb
  • [2023-10-10 14:46:16]
  • 提交

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);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(int i=1;i<=n;i++) if(G[i].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: 52408kb

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

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

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

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: 9ms
memory: 52584kb

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

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: 13ms
memory: 52144kb

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: -100
Wrong Answer
time: 4ms
memory: 52548kb

input:

4 5
1 2
3 4
4 5
5 3

output:

possible

result:

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