QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#695723#7107. ChaleurMine_King#AC ✓182ms11472kbC++142.5kb2024-10-31 20:40:212024-10-31 20:40:22

Judging History

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

  • [2024-10-31 20:40:22]
  • 评测
  • 测评结果:AC
  • 用时:182ms
  • 内存:11472kb
  • [2024-10-31 20:40:21]
  • 提交

answer

// 長い夜の終わりを信じながら
// Think twice, code once.
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define eputchar(c) putc(c, stderr)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define eputs(str) fputs(str, stderr), putc('\n', stderr)
using namespace std;

int T, n, m, vis[100005];
struct graph {
	int tot, hd[100005];
	int nxt[200005], to[200005];

	void clear(int n) {tot = 0; memset(hd, 0, sizeof(int) * n); return;}
	void add(int u, int v) {
		nxt[++tot] = hd[u];
		hd[u] = tot;
		to[tot] = v;
		return;
	}
} g;
int l[100005], p[100005], pos[100005], q[100005];
vector<int> vec[100005];
int deg[100005], cnt[100005];

int main() {
	scanf("%d", &T);
	while (T--) {
		scanf("%d%d", &n, &m);
		for (int i = 1; i <= n; i++) vis[i] = deg[i] = cnt[i] = 0;
		g.clear(n + 5);
		for (int i = 1; i <= m; i++) {
			int u, v;
			scanf("%d%d", &u, &v);
			g.add(u, v), g.add(v, u);
			deg[u]++, deg[v]++;
		}
		for (int i = 1; i <= n; i++) l[i] = 0, pos[i] = vec[0].size(), vec[0].push_back(i);
		for (int i = 1, j = 0; i <= n; i++, j++) {
			while (vec[j].empty()) j--;
			int u = p[i] = vec[j].back();
			vec[j].pop_back();
			pos[u] = -1;
			for (int k = g.hd[u]; k; k = g.nxt[k])
				if (pos[g.to[k]] != -1) {
					int v = g.to[k];
					pos[vec[l[v]].back()] = pos[v];
					swap(vec[l[v]][pos[v]], vec[l[v]].back());
					vec[l[v]].pop_back();
					pos[v] = vec[++l[v]].size();
					vec[l[v]].push_back(v);
				}
		}
		reverse(p + 1, p + n + 1);
		for (int i = 1; i <= n; i++) q[p[i]] = i;
		int mx = 0, id = 0;
		for (int i = 1; i <= n; i++) {
			int num = 1, d = deg[p[i]];
			for (int j = g.hd[p[i]]; j; j = g.nxt[j])
				if (q[g.to[j]] > i) num++, d += deg[g.to[j]];
			d -= num * (num - 1) / 2;
			if (num > mx && d == m) mx = num, id = p[i];
		}
		int ans1 = 1, ans2 = 1;
		vis[id] = 1;
		for (int i = g.hd[id]; i; i = g.nxt[i])
			if (q[g.to[i]] > q[id]) vis[g.to[i]] = 1;
		for (int i = 1; i <= n; i++)
			if (!vis[i]) {
				ans1 += deg[i] == mx - 1;
				for (int j = g.hd[i]; j; j = g.nxt[j])
					if (vis[g.to[j]]) cnt[g.to[j]]++;
			}
		for (int i = 1; i <= n; i++) ans2 += cnt[i] == 1;
		for (int i = 1; i <= n; i++)
			if (vis[i] && !cnt[i]) {
				ans2 = 0;
				for (int i = 1; i <= n; i++) ans2 += vis[i] && !cnt[i];
				break;
			}
		printf("%d %d\n", ans1, ans2);
	}
	return 0;
}
/*
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
*/

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 182ms
memory: 11472kb

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