QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#178648#7107. ChaleurPlentyOfPenalty#AC ✓478ms21384kbC++201.5kb2023-09-14 10:28:012023-09-14 10:28:01

Judging History

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

  • [2023-09-14 10:28:01]
  • 评测
  • 测评结果:AC
  • 用时:478ms
  • 内存:21384kb
  • [2023-09-14 10:28:01]
  • 提交

answer

#include<bits/stdc++.h>
#ifndef memset0
	#define endl '\n'
#endif
using namespace std;
const int N=1e5+9;
int T,n,m,p[N],deg[N];
vector<int> a,b,G[N];
set<int> set_a,set_b;
int solveF(){
	int cnt=0;
	for(int x:b)
		if(G[x].size()==a.size()){
			++cnt;
		}
	if(cnt){
		return cnt;
	}
	cnt=1;
	for(int x:b)
		if(G[x].size()==a.size()-1){
			++cnt;
		}
	return cnt;
}
int solveG(){
	for(int u=1;u<=n;u++){
		deg[u]=0;
		for(int v:G[u])
			if(!set_a.count(v)){
				deg[u]++;
			}
	}
	int cnt=0;
	for(int x:a)
		if(deg[x]==0){
			++cnt;
		}
	if(cnt){
		return cnt;
	}
	cnt=1;
	for(int x:a){
		if(deg[x]==1){
			++cnt;
		}
	}
	return cnt;
}
int main(){
#ifdef memset0
	freopen("F.in","r",stdin);
#endif
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>T;
	while(T--){
		cin>>n>>m;
		for(int i=1;i<=n;i++){
			G[i].clear();
		}
		for(int u,v,i=1;i<=m;i++){
			cin>>u>>v;
			G[u].push_back(v);
			G[v].push_back(u);
		}
		for(int i=1;i<=n;i++){
			p[i]=i;
		}
		sort(p+1,p+n+1,[&](int x,int y){
			return G[x].size()>G[y].size();
		});
		a.clear(),set_a.clear();
		b.clear(),set_b.clear();
		for(int i=1;i<=n;i++){
			int u=p[i];
			int cnt=0;
			for(int v:G[u]){
				if(set_a.count(v)){
					++cnt;
				}
			}
			if(cnt==(int)a.size()){
				a.push_back(u);
				set_a.insert(u);
			}
		}
		for(int i=1;i<=n;i++)
			if(!set_a.count(i)){
				b.push_back(i);
				set_b.insert(i);
			}
		cout<<solveF()<<" "<<solveG()<<endl;
	}
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 5820kb

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: 478ms
memory: 21384kb

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