QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#588843#7107. ChaleurmanaAC ✓143ms30960kbC++202.1kb2024-09-25 14:51:022024-09-25 14:51:03

Judging History

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

  • [2024-09-25 14:51:03]
  • 评测
  • 测评结果:AC
  • 用时:143ms
  • 内存:30960kb
  • [2024-09-25 14:51:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
i64 n, m;
i64 deg[100005];
i64 a[100005];
i64 b[100005];
i64 subb[100005];
i64 vis[100005];
vector<i64> g[100005];
void init(){
	for(int i = 1; i <= n; i++){
		deg[i] = 0;
		subb[i] = i;
		g[i].clear();
	}
}
bool cmp(i64 x, i64 y){
	return deg[x] > deg[y];
}

void solve(){
	cin >> n;
	cin >> m;
	init();
    for(int i = 1; i <= m; i++){
    	cin >> a[i];
    	cin >> b[i];
    	deg[a[i]]++;
    	deg[b[i]]++;
    	g[a[i]].push_back(b[i]);
    	g[b[i]].push_back(a[i]);
    }
    sort(subb+1,subb+1+n,cmp);
    i64 sub;
    vector<i64> g1;
    vector<i64> g2;
    g1.clear();
    g2.clear();
    for(int i = 1; i <= n; i++){
    	sub = subb[i];
    	if(deg[sub] >= i-1){
    		g1.push_back(sub);
    	}
    	else{
    		g2.push_back(sub);
    	}
    }
    i64 res1 = 1;
    i64 res2 = 1;
    i64 x, y, flag, num;
    for(int i = 0; i < g2.size(); i++){
    	x = g2[i];
    	if(deg[x] != g1.size() - 1){
    		continue;
    	}
    	flag = 1;
    	num = 0;
    	for(int j = 0; j < g1.size(); j++){
    		y = g1[j];
    		vis[y] = 0;
    	}
    	for(int j = 0; j < g[x].size(); j++){
    		y = g[x][j];
    		vis[y] = 1;
    	}
    	for(int j = 0; j < g1.size(); j++){
    		y = g1[j];
    		if(vis[y] == 1){
    			num++;
    		}
    		else{
    			/*
    			if(deg[y] != g1.size() - 1){
    				flag = 0;
    			}
    			*/
    		}
    	}
    	if(num != g1.size() - 1){
    		flag = 0;
    	}
    	if(flag){
    		res1++;
    	}
    }
    
    flag = 1;
    i64 num1 = 0;
    i64 num2 = 0;
    for(int i = 0; i < g1.size(); i++){
    	x = g1[i];
    	if(deg[x] == g1.size() - 1){
    		flag = 2;
    		num1++;
    	}
    	if(deg[x] == g1.size()){
    		num2++;
    	}
    }
    if(flag == 1){
    	res2 = num2 + 1;
    }
    else{
    	res2 = num1;
    }
    
    cout << res1 << ' ' << res2 << endl;
    return;
}
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

	long long tt = 1;
	cin >> tt;
	while(tt--){
		solve();
	}

    return 0;
}


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

详细

Test #1:

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

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: 143ms
memory: 30960kb

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