QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#208467#5160. Kebab PizzaAeren#WA 2ms11652kbC++201.3kb2023-10-09 17:12:142023-10-09 17:12:14

Judging History

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

  • [2023-10-09 17:12:14]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11652kb
  • [2023-10-09 17:12:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

int n, k, chk[100100], chk2[100100];
set<int> s[100100];
vector<int> v[100100];

int dfs(int u) {
	if(chk2[u]) return 0;
	chk2[u] = 1;

	int re = (int)v[u].size() - 2;
	for(auto x : v[u]) re += dfs(x);
	return re;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> k >> n;
	for(int i=1;i<=k;i++) {
		int a, b; cin >> a >> b;
		s[a].insert(b), s[b].insert(a);
	}

	vector<array<int, 2>> p(n);
	for(int i=1;i<=n;i++) p[i-1] = {s[i].size(), i};
	sort(p.rbegin(), p.rend());
	
	int line = 0, cycle = 0;

	for(auto [SSSS, u] : p) if(!chk[u]) {

		for(auto x : s[u]) {
			if(x == u) {

			} else if(s[x].size() == 1) {
				chk[x] = 1;
			} else {
				v[u].push_back(x);
			}
		}

		if(v[u].size() > 2) return cout << "impossible\n", 0;
		if(v[u].empty()) line++;
	}

	// for(int i=1;i<=n;i++) if(!chk[i]) {
	// 	cout << i << " / ";
	// 	for(auto x : v[i]) cout << x << " ";
	// 		cout << "\n";
	// }

	for(int i=1;i<=n;i++) if(!chk[i] && !chk2[i]) {
		// cout << i << " " << dfs(i) << "\n";
		if(dfs(i)) line++;
		else cycle++;
	}

	// cout << "[" << cycle << " " << line << "]\n";

	if(cycle) {
		cout << (cycle+line != 1 ? "impossible" : "possible");
	} else {
		cout << "possible";
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 10924kb

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: 2ms
memory: 10964kb

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: 2ms
memory: 10632kb

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: 2ms
memory: 10748kb

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

input:

4 4
1 2
2 1
3 4
4 3

output:

possible

result:

ok single line: 'possible'

Test #6:

score: 0
Accepted
time: 1ms
memory: 10924kb

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

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: 0
Accepted
time: 2ms
memory: 10616kb

input:

4 5
1 2
3 4
4 5
5 3

output:

impossible

result:

ok single line: 'impossible'

Test #9:

score: 0
Accepted
time: 2ms
memory: 10656kb

input:

4 4
1 1
2 3
3 4
4 2

output:

impossible

result:

ok single line: 'impossible'

Test #10:

score: -100
Wrong Answer
time: 2ms
memory: 11652kb

input:

3 4
1 2
2 3
3 1

output:

impossible

result:

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