QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#209712#7107. ChaleurLeasierAC ✓35ms2100kbC++981.4kb2023-10-10 16:45:372023-10-10 16:45:39

Judging History

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

  • [2023-10-10 16:45:39]
  • 评测
  • 测评结果:AC
  • 用时:35ms
  • 内存:2100kb
  • [2023-10-10 16:45:37]
  • 提交

answer

#include <algorithm>
#include <vector>
#include <cstdio>

using namespace std;

int deg[100007], p[100007];
bool mark[100007];

inline void init(int n){
	for (int i = 1; i <= n; i++){
		deg[i] = 0;
	}
}

inline int read(){
	int ans = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9'){
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9'){
		ans = ans * 10 + (ch ^ 48);
		ch = getchar();
	}
	return ans;
}

void write(int n){
	if (n >= 10) write(n / 10);
	putchar(n % 10 + '0');
}

bool cmp(const int a, const int b){
	return deg[a] > deg[b];
}

int main(){
	int t = read();
	for (int i = 1; i <= t; i++){
		int n = read(), m = read();
		if (m == 0){
			write(n);
			putchar(' ');
			putchar('1');
			putchar('\n');
			continue;
		}
		int cnt = 1, ans1 = 1, ans2 = 0;
		init(n);
		for (int j = 1; j <= m; j++){
			int a = read(), b = read();
			deg[a]++;
			deg[b]++;
		}
		for (int j = 1; j <= n; j++){
			p[j] = j;
		}
		sort(p + 1, p + n + 1, cmp);
		while (cnt < n && !(deg[p[cnt]] >= cnt - 1 && deg[p[cnt + 1]] <= cnt - 1)) cnt++;
		for (int j = cnt + 1; j <= n && deg[p[j]] == cnt - 1; j++){
			ans1++;
		}
		for (int j = cnt; j >= 1 && deg[p[j]] == cnt - 1; j--){
			ans2++;
		}
		if (ans2 == 0){
			ans2 = 1;
			for (int j = cnt; j >= 1 && deg[p[j]] == cnt; j--){
				ans2++;
			}
		}
		write(ans1);
		putchar(' ');
		write(ans2);
		putchar('\n');
	}
	return 0;
}

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

详细

Test #1:

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

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: 35ms
memory: 2100kb

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