QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#201589#5160. Kebab Pizzanameless_story#WA 0ms3872kbC++201.7kb2023-10-05 15:19:432023-10-05 15:19:44

Judging History

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

  • [2023-10-05 15:19:44]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3872kb
  • [2023-10-05 15:19:43]
  • 提交

answer

#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T1,class T2> bool cmin(T1 &x,const T2 &y) { if (y<x) { x=y; return 1; }return 0; }
template<class T1,class T2> bool cmax(T1 &x,const T2 &y) { if (x<y) { x=y; return 1; }return 0; }
#define all(x) (x).begin(),(x).end()
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cout<<fixed<<setprecision(15);
	auto cal=[&]()
		{
			int n,m,i,j;
			cin>>m>>n;
			vector<pair<int,int>> eg;
			vector<int> single(n+1);
			while (m--)
			{
				int x,y;
				// cin>>x>>y;
				cin>>x>>y;
				if (x==y) single[x]=1;
				else
				{
					if (x>y) swap(x,y);
					eg.push_back({x,y});
				}
			}
			sort(all(eg)); eg.resize(unique(all(eg))-eg.begin());
			vector<int> cnt(n+1);
			for (auto [x,y]:eg) ++cnt[x],++cnt[y];
			vector e(n+1,vector<int>());
			vector<int> f(n+1);
			iota(all(f),0);
			function<int(int)> getf=[&](int u) { return f[u]==u?u:f[u]=getf(f[u]); };
			vector id(n+1,vector<int>());
			vector<int> sum(n+1);
			for (auto [x,y]:eg) if (cnt[x]+single[x]>1&&cnt[y]+single[y]>1)
			{
				e[x].push_back(y);
				e[y].push_back(x);
				f[getf(x)]=getf(y);
			}
			for (i=1; i<=n; i++) if (e[i].size()>=3) return 0;
			for (i=1; i<=n; i++) sum[getf(i)]+=e[i].size(),id[getf(i)].push_back(i);
			vector<int> loop;
			for (i=1; i<=n; i++) if (id[i].size()>1&&sum[i]==id[i].size()*2) loop.push_back(i);
			if (loop.size()>=2) return 0;
			if (loop.size()==1)
			{
				int x=loop[0];
				for (i=1; i<=n; i++) if ((e[i].size()||single[i])&&getf(i)!=x) return 0;
				return 1;
			}
			return 1;
		};
	if (cal()) cout<<"possible\n";
	else cout<<"impossible\n";
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3856kb

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

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

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

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

input:

4 4
1 2
2 1
3 4
4 3

output:

possible

result:

ok single line: 'possible'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3564kb

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

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

input:

4 5
1 2
3 4
4 5
5 3

output:

possible

result:

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