QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#368966#2437. Wireless is the New FiberInfinityNS#AC ✓10ms4272kbC++14916b2024-03-27 18:36:212024-03-27 18:36:36

Judging History

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

  • [2024-03-27 18:36:36]
  • 评测
  • 测评结果:AC
  • 用时:10ms
  • 内存:4272kb
  • [2024-03-27 18:36:21]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N=1000050;
int deg[N];
int main(){
	int n,m;
	scanf("%i %i",&n,&m);
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%i %i",&u,&v);
		deg[u]++;
		deg[v]++;
	}
	vector<int> ids;
	for(int i=0;i<n;i++)ids.push_back(i);
	sort(ids.begin(),ids.end(),[&](int i,int j){return deg[i]>deg[j];});
	int need=n*2-2;
	int now=m*2;
	int ans=0;
	for(int i:ids){
		if(need<now){
			int take=min(deg[i]-1,now-need);
			now-=take;
			deg[i]-=take;
			ans++;
		}
	}
	sort(ids.begin(),ids.end(),[&](int i,int j){return deg[i]>deg[j];});
	vector<pair<int,int>> edges;
	int ptr=0;
	for(int i=0;i<ids.size();i++){
		while(deg[ids[i]]){
			ptr++;
			deg[ids[ptr]]--;
			deg[ids[i]]--;
			edges.push_back({ids[i],ids[ptr]});
		}
	}
	printf("%i\n",ans);
	printf("%i %i\n",n,n-1);
	for(auto p:edges)printf("%i %i\n",p.first,p.second);
	return 0;
}

Details

Test #1:

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

Test #2:

score: 0
Accepted
time: 0ms
memory: 3844kb

Test #3:

score: 0
Accepted
time: 1ms
memory: 3804kb

Test #4:

score: 0
Accepted
time: 0ms
memory: 3816kb

Test #5:

score: 0
Accepted
time: 0ms
memory: 3768kb

Test #6:

score: 0
Accepted
time: 0ms
memory: 4072kb

Test #7:

score: 0
Accepted
time: 0ms
memory: 4068kb

Test #8:

score: 0
Accepted
time: 0ms
memory: 3784kb

Test #9:

score: 0
Accepted
time: 1ms
memory: 4068kb

Test #10:

score: 0
Accepted
time: 0ms
memory: 3740kb

Test #11:

score: 0
Accepted
time: 1ms
memory: 3800kb

Test #12:

score: 0
Accepted
time: 1ms
memory: 3764kb

Test #13:

score: 0
Accepted
time: 1ms
memory: 4076kb

Test #14:

score: 0
Accepted
time: 1ms
memory: 3784kb

Test #15:

score: 0
Accepted
time: 1ms
memory: 4040kb

Test #16:

score: 0
Accepted
time: 1ms
memory: 3832kb

Test #17:

score: 0
Accepted
time: 0ms
memory: 3836kb

Test #18:

score: 0
Accepted
time: 9ms
memory: 4032kb

Test #19:

score: 0
Accepted
time: 2ms
memory: 3968kb

Test #20:

score: 0
Accepted
time: 3ms
memory: 3992kb

Test #21:

score: 0
Accepted
time: 4ms
memory: 3944kb

Test #22:

score: 0
Accepted
time: 4ms
memory: 3960kb

Test #23:

score: 0
Accepted
time: 6ms
memory: 3980kb

Test #24:

score: 0
Accepted
time: 3ms
memory: 3980kb

Test #25:

score: 0
Accepted
time: 3ms
memory: 4264kb

Test #26:

score: 0
Accepted
time: 9ms
memory: 3980kb

Test #27:

score: 0
Accepted
time: 9ms
memory: 3960kb

Test #28:

score: 0
Accepted
time: 10ms
memory: 3972kb

Test #29:

score: 0
Accepted
time: 8ms
memory: 4272kb

Test #30:

score: 0
Accepted
time: 1ms
memory: 3840kb

Test #31:

score: 0
Accepted
time: 1ms
memory: 3780kb

Test #32:

score: 0
Accepted
time: 0ms
memory: 3740kb

Test #33:

score: 0
Accepted
time: 5ms
memory: 3784kb

Test #34:

score: 0
Accepted
time: 1ms
memory: 3788kb

Test #35:

score: 0
Accepted
time: 1ms
memory: 3728kb

Test #36:

score: 0
Accepted
time: 0ms
memory: 3760kb

Test #37:

score: 0
Accepted
time: 0ms
memory: 4056kb