厌 氧 程 序
查看原帖
厌 氧 程 序
248302
d0j1a_1701楼主2021/1/26 10:26

相同的代码 不开O2 80分 开O2 全TLE0分???

无O2

O2

#include <unordered_map>
#include <iostream>
#include <bitset>
#include <list>
using namespace std;
unordered_map<string,int> cnt,id;
string buf1,buf2;
int odd,len=1;
bitset<500010> vis;
list<int> l[500010];
int getid(string str){
	if(!id.count(str))	id[str] = len++;
	return id[str];
}
bool dfs(int x){
	vis[x] = 1;
	for(auto to:l[x])
		if(!vis[to])	dfs(to);
}
int main(){
	while(cin >> buf1 >> buf2){
		cnt[buf1]++;
		cnt[buf2]++;
		int a=getid(buf1),b=getid(buf2);
		if(a==b)	continue;
		l[a].push_back(b);
		l[b].push_back(a);
	}
	for(auto x:cnt){
		odd += x.second&1;
	}
	dfs(1);
	if(odd>2||odd==1||vis.count()!=len-1||len==0)	cout << "Impossible" << endl;
	else	cout << "Possible" << endl;
	return 0;
}
2021/1/26 10:26
加载中...