QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#209400#7107. ChaleurzqsWA 509ms24976kbC++142.9kb2023-10-10 14:52:252023-10-10 14:52:26

Judging History

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

  • [2023-10-10 14:52:26]
  • 评测
  • 测评结果:WA
  • 用时:509ms
  • 内存:24976kb
  • [2023-10-10 14:52:25]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#define gc (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++)

char buf[100000], *p1, *p2;
inline int read() {
	char ch; int x = 0; while ((ch = gc) < 48); do x = x * 10 + ch - 48; while ((ch = gc) >= 48); return x;
}
int deg[100005], a[100005], bel[100005], seq[100005], n, m;
bool vaild[100005], vis[100005];
std::vector<int> G[100005], vec[100005];
int adjust1() {
	int cnt = 0;
	for (int i = 1; i <= n; ++ i) if (bel[i]) ++ cnt;
	for (int i = 1; i <= n; ++ i) if (!bel[i]) {
		int x = 0;
		for (int j : G[i]) if (bel[j]) ++ x;
		if (x == cnt) return i;
	}
	return 0;
}
int adjust2() {
	for (int i = 1; i <= n; ++ i) if (bel[i]) {
		bool flag = true;
		for (int j : G[i]) if (!bel[j]) {flag = false; break;}
		if (flag) return i;
	}
	return 0;
}
int calc1() {
	memset(vis, false, sizeof vis);
	int cnt = 0, ans = 1;
	for (int i = 1; i <= n; ++ i) if (bel[i]) seq[++ cnt] = i;
	for (int i = 1; i <= n; ++ i) if (!bel[i] && deg[i] >= cnt - 1) {
		int tot = 0;
		for (int j : G[i]) vis[j] = true, tot += bel[j];
		if (tot == cnt - 1) {
			int v = 0;
			for (int j = 1; j <= cnt; ++ j) if (!vis[seq[j]]) {v = seq[j]; break;}
			if (deg[v] == cnt - 1) ++ ans;
		}
		for (int j : G[i]) vis[j] = false;
	}
	return ans;
}
int calc2() {
	memset(vis, false, sizeof vis);
	int cnt = 0, ans = 1;
	for (int i = 1; i <= n; ++ i) if (bel[i]) ++ cnt;
	for (int i = 1; i <= n; ++ i) if (bel[i] && deg[i] == cnt) ++ ans;
	return ans;
}

int main() {
	int _ = read();
	while (_ --) {
		memset(deg, 0, sizeof deg);
		n = read(), m = read();
		for (int i = 0; i <= n; ++ i) vec[i].clear(), G[i].clear(), deg[i] = bel[i] = 0;
		std::set<std::pair<int, int> > S;
		int jb = 0;
		for (int i = 1, u, v; i <= m; ++ i) {
			u = read(), v = read();
			if (u > v) u ^= v ^= u ^= v;
			if (S.count(std::make_pair(u, v))) continue;
			S.insert(std::make_pair(u, v)), ++ jb;
			G[u].emplace_back(v), G[v].emplace_back(u), ++ deg[u], ++ deg[v];
		}
		if (!m) {printf("%d 1\n", n); continue;}
		if (jb == 1ll * n * (n - 1) >> 1) {printf("1 %d\n", n); continue;}
		for (int i = 1; i <= n; ++ i) vec[deg[i]].emplace_back(i);
		for (int i = 0, k = 0; i <= n; ++ i) for (int j : vec[i]) a[++ k] = j;
		memset(vis, false, sizeof vis);
		int r = 0, l = n;
		for (int i = n; i; -- i) {
			int x = 0;
			for (int j : G[a[i]]) if (vis[j]) ++ x;
			vis[a[i]] = true;
			if (x != n - i) {r = i + 1; break;}
		}
		memset(vis, false, sizeof vis);
		for (int i = 1; i <= n; ++ i) {
			for (int j : G[a[i]]) if (vis[j]) {l = i - 1; break;}
			if (l != n) break;
			vis[a[i]] = true;
		}
		for (int i = l + 1; i <= n; ++ i) bel[a[i]] = 1;
		int t = adjust1(); bel[t] = 1; printf("%d ", calc1());
		bel[t] = 0; bel[adjust2()] = 0; printf("%d\n", calc2());
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Wrong Answer
time: 509ms
memory: 24976kb

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:

wrong answer 1013th lines differ - expected: '2 1', found: '1 1'