QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#157035#7107. Chaleurucup-team1477#AC ✓160ms11508kbC++171.2kb2023-09-02 14:48:272023-09-02 15:00:22

Judging History

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

  • [2023-09-02 15:00:22]
  • 评测
  • 测评结果:AC
  • 用时:160ms
  • 内存:11508kb
  • [2023-09-02 14:48:27]
  • 提交

answer

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

void solve() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> adj(n);
	vector<pair<int, int>> edge(m);
	for (auto &[u, v] : edge) {
		cin >> u >> v;
		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	vector<vector<int>> d(n);
	for (int i = 0; i < n; i++) {
		d[adj[i].size()].push_back(i);
	}
	vector<bool> clique(n);
	int sz = 0;
	for (int i = n - 1; i >= 0; i--) {
		for (int x : d[i]) {
			int cnt = 0;
			for (int y : adj[x]) {
				cnt += clique[y];
			}
			if (cnt == sz) {
				clique[x] = 1;
				sz++;
			}
		}
	}
	int ans = 1;
	vector<int> in(n), out(n);
	for (auto [u, v] : edge) {
		if (clique[u] && !clique[v]) {
			in[u]++;
			out[v]++;
		} else if (clique[v] && !clique[u]) {
			in[v]++;
			out[u]++;
		}
	}
	for (int i = 0; i < n; i++) {
		if (!clique[i] && out[i] == sz - 1) {
			ans++;
		}
	}
	int c0 = 0, c1 = 0;
	for (int i = 0; i < n; i++) {
		if (clique[i]) {
			if (!in[i]) {
				c0++;
			} else if (in[i] == 1) {
				c1++;
			}
		}
	}
	cout << ans << " " << (c0 ? c0 : c1 + 1) << "\n";
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	int T;
	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3568kb

input:

3
3 2
1 2
2 3
6 6
1 2
2 3
1 3
1 4
2 5
3 6
4 1
1 2

output:

2 1
1 4
1 2

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 160ms
memory: 11508kb

input:

2231
1 0
5 7
4 1
3 4
3 1
3 5
4 2
3 2
4 5
5 4
2 1
2 5
2 4
2 3
5 10
3 2
2 5
1 4
4 2
4 5
1 2
1 3
3 5
3 4
1 5
5 10
1 3
2 4
1 4
5 2
2 3
1 5
5 4
1 2
3 4
5 3
5 9
2 5
3 5
2 3
2 1
4 3
3 1
4 1
4 5
2 4
5 4
4 2
4 1
4 5
4 3
5 9
4 1
4 5
3 4
2 4
2 1
3 1
2 5
3 5
3 2
5 4
2 5
2 3
2 1
2 4
5 9
5 2
1 3
4 3
1 2
5 4
4 2
5...

output:

1 1
3 1
4 1
1 5
1 5
2 1
4 1
2 1
4 1
2 1
2 1
3 1
4 1
4 1
1 5
2 1
4 1
1 5
1 5
1 5
3 1
4 1
4 1
4 1
3 1
3 1
4 1
4 1
2 1
4 1
4 1
1 5
1 5
2 1
4 1
4 1
4 1
3 1
2 1
4 1
2 1
4 1
4 1
4 1
3 1
1 5
4 1
4 1
1 5
2 1
4 1
2 1
2 1
1 5
4 1
1 5
3 1
4 1
1 5
2 1
1 5
3 1
3 1
1 5
3 1
3 1
2 1
1 5
4 1
3 1
1 5
2 1
3 1
2 1
2 1
...

result:

ok 2231 lines

Extra Test:

score: 0
Extra Test Passed