QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#217960 | #2437. Wireless is the New Fiber | Kronos# | AC ✓ | 29ms | 4052kb | C++17 | 1.6kb | 2023-10-17 16:36:49 | 2023-10-17 16:36:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e6+5;
signed main() {
// ios_base::sync_with_stdio(0);
// cin.tie(0);
int n;
int m;
cin>>n>>m;
vector<int> deg(n,0),ndeg(n,1);
vector<int> a,b;
for(int i=0;i<m;i++){
int u,v;
cin>>u>>v;
deg[u]++;
deg[v]++;
}
for(int i=0;i<n;i++){
a.push_back(i);
b.push_back(i);
}
sort(a.begin(),a.end(),[&](int x, int y) {
return deg[x]<deg[y];
});
int rem=n-2;
int curr=0;
int ans=0;
while(curr<n){
int x=deg[a[curr]];
x--;
if(x>rem){
ndeg[a[curr]]+=rem;
rem=0;
break;
}
else{
ndeg[a[curr]]+=x;
rem-=x;
ans++;
}
curr++;
}
// cout<<ans<<"\n";
// cout<<rem<<"\n";
// cout<<"done\n";
// for(auto it:ndeg) cout<<it<<" ";
// cout<<"\n";
sort(b.begin(),b.end(),[&](int x, int y) {
return ndeg[x]>ndeg[y];
});
curr=1;
vector<pair<int,int>> ed;
for(int i=0;i<n;i++){
int val=ndeg[b[i]];
// cout<<b[i]<<" "<<val<<"\n";
while(val){
ed.push_back({b[i],b[curr]});
ndeg[b[curr]]--;
val--;
curr++;
//cout<<curr<<"\n";
}
}
assert(ed.size()==n-1);
cout<<n-ans<<"\n";
cout<<n<<" "<<n-1<<"\n";
for(auto it:ed) cout<<it.first<<" "<<it.second<<"\n";
}
Details
Test #1:
score: 100
Accepted
time: 0ms
memory: 3772kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 3644kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 3500kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 3604kb
Test #5:
score: 0
Accepted
time: 0ms
memory: 3608kb
Test #6:
score: 0
Accepted
time: 0ms
memory: 3612kb
Test #7:
score: 0
Accepted
time: 0ms
memory: 3620kb
Test #8:
score: 0
Accepted
time: 0ms
memory: 3652kb
Test #9:
score: 0
Accepted
time: 0ms
memory: 3608kb
Test #10:
score: 0
Accepted
time: 0ms
memory: 3840kb
Test #11:
score: 0
Accepted
time: 1ms
memory: 3620kb
Test #12:
score: 0
Accepted
time: 2ms
memory: 3584kb
Test #13:
score: 0
Accepted
time: 1ms
memory: 3868kb
Test #14:
score: 0
Accepted
time: 1ms
memory: 3584kb
Test #15:
score: 0
Accepted
time: 1ms
memory: 3640kb
Test #16:
score: 0
Accepted
time: 1ms
memory: 3804kb
Test #17:
score: 0
Accepted
time: 3ms
memory: 3840kb
Test #18:
score: 0
Accepted
time: 24ms
memory: 3644kb
Test #19:
score: 0
Accepted
time: 4ms
memory: 4036kb
Test #20:
score: 0
Accepted
time: 5ms
memory: 3776kb
Test #21:
score: 0
Accepted
time: 8ms
memory: 4052kb
Test #22:
score: 0
Accepted
time: 10ms
memory: 3696kb
Test #23:
score: 0
Accepted
time: 13ms
memory: 3808kb
Test #24:
score: 0
Accepted
time: 16ms
memory: 3976kb
Test #25:
score: 0
Accepted
time: 20ms
memory: 3972kb
Test #26:
score: 0
Accepted
time: 22ms
memory: 3808kb
Test #27:
score: 0
Accepted
time: 24ms
memory: 3696kb
Test #28:
score: 0
Accepted
time: 24ms
memory: 4032kb
Test #29:
score: 0
Accepted
time: 29ms
memory: 3812kb
Test #30:
score: 0
Accepted
time: 0ms
memory: 3492kb
Test #31:
score: 0
Accepted
time: 0ms
memory: 3580kb
Test #32:
score: 0
Accepted
time: 0ms
memory: 3604kb
Test #33:
score: 0
Accepted
time: 17ms
memory: 3644kb
Test #34:
score: 0
Accepted
time: 0ms
memory: 3808kb
Test #35:
score: 0
Accepted
time: 0ms
memory: 3608kb
Test #36:
score: 0
Accepted
time: 0ms
memory: 3612kb
Test #37:
score: 0
Accepted
time: 0ms
memory: 3848kb