诡异代码求条,玄关
查看原帖
诡异代码求条,玄关
374443
shawn0618楼主2025/8/29 14:46
#include <bits/stdc++.h>
#define _ return 0;
//#define map unordered_map
//#define set unordered_set
using namespace std;

int n,m;
unordered_map <string,int> rdu,cdu,vis;
string root="red";
unordered_set <string> thing;
unordered_map <string,vector<string> > g;
queue <string> q;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string u,v;
	while (cin>>u){
		cin>>v;
		root=u,thing.insert(u),thing.insert(v);
		g[u].push_back(v);
		rdu[u]++,cdu[v]++;
	}
	int flag=0,r=0,c=0;
	string f=root;
	for (auto i:thing){
		if (rdu[i]!=cdu[i]){
			flag=1;
			if (rdu[i]-cdu[i]==1)  r++,f=i;
			else if (cdu[i]-rdu[i]==1)  c++;
			else{cout<<"Impossible";_}
		}
	}
	if (flag && !(r==c && c==1)){cout<<"Impossible";_}
	q.push(root);
	while (!q.empty()){
		u=q.front();
		vis[u]=1;
		for (auto v:g[u])  if (!vis[v])  q.push(v);
		q.pop();
	}
	for (auto i:thing){
		if (!vis[i]){cout<<"Impossible";_}
	}
	cout<<"Possible";_
}

8AC+1WA#8+1MLE#10

2025/8/29 14:46
加载中...