QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#209389#5160. Kebab Pizza275307894aWA 4ms52660kbC++141.5kb2023-10-10 14:48:272023-10-10 14:48:27

Judging History

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

  • [2023-10-10 14:48:27]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:52660kb
  • [2023-10-10 14:48:27]
  • 提交

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(i=1;i<=n;i++) if(G[i].size()==1) flag=0;
	for(i=1;i<=n;i++) if(S[i].size()&&!G[i].size()) 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: 4ms
memory: 51452kb

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

input:

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

output:

impossible

result:

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