80?!(
查看原帖
80?!(
450743
XOOR楼主2023/4/7 18:59
#include<iostream>
#include<map>
#include<vector>
#include<cstdio>
#include<string>
#include<iostream>
using namespace std;
const int sed=10086,MODq=1e6+7,N=1e6+10;
int f[N],d[N],h[N];
int n,m,ans,cnt,tot;
string s1,s2;
int find(int x){
	return f[x]==x?x:f[x]=find(f[x]);
}
bool merge(int x,int y){
	int fx=find(x),fy=find(y);
	if(fx==fy) return 0;
	f[fx]=fy;
	return 1;
//    return ;
}
int H(string x){
	int t=0;
	for(int i=0;i<x.size();i++) t=(1ll*t*sed+(long long)x[i])%MODq;
	return t;
}
void solve(){
    while(cin>>s1>>s2){
    	int x=H(s1),y=H(s2);
    	if(!d[x]) f[x]=x,h[++tot]=x;
    	if(!d[y]) f[y]=y,h[++tot]=y;
    	if(merge(x,y)) cnt++;
    	d[x]++,d[y]++;
    }
    for(int i=1;i<=tot;i++) if(d[h[i]]&1) ans++;
    if(cnt<n-1 || (ans!=2 && ans!=0)) puts("Impossible");
    else puts("Possible");
	return ;
}
int main() {
    solve();
    return 0;
}
2023/4/7 18:59
加载中...