QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#134843 | #6634. Central Subset | PhantomThreshold# | WA | 21ms | 8172kb | C++20 | 1.0kb | 2023-08-05 09:15:43 | 2023-08-05 09:15:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn=200000;
int T;
int n,m;
vector<int> g[maxn+50];
int dis[maxn+50];
int main(){
ios_base::sync_with_stdio(false);
cin >> T;
for (;T--;){
cin >> n >> m;
int S=sqrt(n);
for (;S*S<n;) S++;
for (;(S-1)*(S-1)>=n;) S--;
int B=n/S;
for (int i=1;i<=m;i++){
int x,y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
for (int i=1;i<=n;i++) dis[i]=-1;
queue<int> q;
q.push(1);
dis[1]=0;
for (;!q.empty();){
int u=q.front();
q.pop();
for (auto v:g[u]){
if (dis[v]!=-1) continue;
dis[v]=dis[u]+1;
q.push(v);
}
}
vector<pair<int,int>> perm(n+1);
for (int i=1;i<=n;i++) perm[i]=make_pair(dis[i],i);
sort(perm.begin()+1,perm.begin()+n);
vector<int> ans;
for (int i=1;i<=S;i++) ans.push_back(perm[(i-1)*B+1].second);
cout << ans.size() << "\n";
for (auto e:ans) cout << e << " ";
cout << "\n";
for (int i=1;i<=n;i++){
dis[i]=-1;
g[i].clear();
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8168kb
input:
2 4 3 1 2 2 3 3 4 6 7 1 2 2 3 3 1 1 4 4 5 5 6 6 4
output:
2 1 3 3 1 3 5
result:
ok correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 21ms
memory: 8172kb
input:
10000 15 14 13 12 5 4 9 8 11 12 15 14 10 9 14 13 2 3 2 1 6 5 10 11 3 4 7 6 8 7 6 5 2 1 2 4 4 6 2 3 3 5 10 9 8 3 9 4 5 6 5 10 3 2 5 4 2 7 1 2 4 3 2 1 2 1 2 1 2 1 9 8 9 8 5 4 1 2 6 5 3 4 3 2 7 8 7 6 2 1 1 2 14 13 3 10 5 6 2 9 11 4 2 3 2 1 8 7 13 6 5 4 5 12 6 7 4 3 7 14 16 15 2 3 2 1 6 10 6 9 6 4 9 11 ...
output:
4 1 4 7 10 3 1 3 5 4 1 3 4 5 2 1 2 2 1 2 3 1 4 7 2 1 2 4 1 9 5 12 4 1 5 9 13 4 1 5 9 13 5 1 5 9 13 17 3 1 3 5 4 1 3 4 5 5 1 4 7 10 13 3 1 2 3 4 1 4 7 10 3 1 3 5 2 1 2 3 1 4 7 5 1 4 7 10 13 2 1 3 3 1 3 4 4 1 9 5 12 5 1 4 7 10 13 3 1 3 5 4 1 4 7 10 3 1 3 4 4 1 4 6 8 2 1 2 ...
result:
wrong answer Condition failed: "getMaxBfsDist(n, subset) <= csqrtn" (test case 1)