QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#209416#7107. ChaleurLeasierWA 210ms7156kbC++113.4kb2023-10-10 14:55:582023-10-10 14:55:59

Judging History

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

  • [2023-10-10 14:55:59]
  • 评测
  • 测评结果:WA
  • 用时:210ms
  • 内存:7156kb
  • [2023-10-10 14:55:58]
  • 提交

answer

#include <stdio.h>

#include <vector>

using namespace std;

typedef struct {
	int nxt;
	int end;
} Edge;

int cnt;
int head[100007], deg[100007], root[100007], sz[100007];
bool mark[100007], mark2[100007];
Edge edge[200007];

inline void init(int n){
	cnt = 0;
	for (int i = 1; i <= n; i++){
		head[i] = deg[i] = 0;
		root[i] = i;
		sz[i] = 1;
		mark[i] = mark2[i] = false;
	}
}

inline void add_edge(int start, int end){
	cnt++;
	edge[cnt].nxt = head[start];
	head[start] = cnt;
	edge[cnt].end = end;
}

int get_root(int x){
	if (root[x] == x) return x;
	return root[x] = get_root(root[x]);
}

inline void merge(int x, int y){
	int x_root = get_root(x), y_root = get_root(y);
	if (x_root != y_root){
		root[x_root] = y_root;
		sz[y_root] += sz[x_root];
	}
}

inline void update(int p, int q, int &x, int &y){
	if (x < p){
		x = p;
		y = q;
	} else if (x == p){
		y += q;
	}
}

int main(){
	int t;
	scanf("%d", &t);
	for (int i = 1; i <= t; i++){
		int n, m;
		scanf("%d %d", &n, &m);
		if (m == 0){
			printf("%d 1\n", n);
			continue;
		}
		int ncon = 0;
		init(n);
		for (int j = 1; j <= m; j++){
			int a, b;
			scanf("%d %d", &a, &b);
			deg[a]++;
			deg[b]++;
			add_edge(a, b);
			add_edge(b, a);
			merge(a, b);
		}
		vector<int> tuan, must, candiate;
		for (int j = 1; j <= n; j++){
			int csz = sz[get_root(j)];
			if (csz == 1){
				ncon++;
			} else {
				tuan.push_back(j);
			}
		}
		int mxv = 0, cnt;
		while (1ll * mxv * (mxv + 1) / 2 <= m) mxv++;
		for (int j = mxv; j >= 2; j--){
			vector<int> _must, _candiate;
			for (int k : tuan){
				mark[k] = false;
			}
			for (int k : tuan){
				if (deg[k] == j - 1){
					for (int l = head[k]; l != 0; l = edge[l].nxt){
						mark[edge[l].end] = true;
					}
				} else if (deg[k] >= j){
					mark[k] = true;
				}
			}
			for (int k : tuan){
				if (deg[k] >= j - 1){
					if (mark[k]){
						_must.push_back(k);
					} else {
						_candiate.push_back(k);
					}
				}
			}
			if (_candiate.size() == 1){
				_must.push_back(_candiate[0]);
				_candiate.pop_back();
			}
			if (_must.size() > j || _must.size() + _candiate.size() < j) continue;
			cnt = j;
			must = _must;
			candiate = _candiate;
			break;
		}
		int cnt1 = -1, ans1, cnt2 = -1, ans2;
		for (int j : tuan){
			mark[j] = mark2[j] = false;
		}
		if (must.size() == cnt){
			for (int j : must){
				mark[j] = true;
			}
			update(cnt, 1, cnt1, ans1);
			for (int k : must){
				for (int l = head[k]; l != 0; l = edge[l].nxt){
					if (!mark[edge[l].end]) update(2, 1, cnt1, ans1);
				}
			}
			update(n - cnt, 1, cnt2, ans2);
			for (int k : must){
				int tot = n - cnt + 1;
				for (int l = head[k]; l != 0; l = edge[l].nxt){
					if (!mark[edge[l].end]) tot--;
				}
				update(tot, 1, cnt2, ans2);
			}
		} else {
			for (int j : must){
				mark[j] = true;
			}
			for (int j : candiate){
				mark2[j] = true;
			}
			update(cnt, candiate.size(), cnt1, ans1);
			for (int k : must){
				for (int l = head[k]; l != 0; l = edge[l].nxt){
					int x = edge[l].end;
					if (!mark[x] && !mark2[x]) update(2, 1, cnt1, ans1);
				}
			}
			update(n - must.size(), 1, cnt2, ans2);
			for (int k : must){
				int tot = n - cnt + 1;
				for (int l = head[k]; l != 0; l = edge[l].nxt){
					if (!mark[edge[l].end]) tot--;
				}
				update(tot, 1, cnt2, ans2);
			}
		}
		printf("%d %d\n", ans1, ans2);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 210ms
memory: 7156kb

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: '0 1'