QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#127157 | #6634. Central Subset | yy_zq# | WA | 18ms | 8684kb | C++14 | 889b | 2023-07-19 13:37:14 | 2023-07-19 13:37:18 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,j,k) for(int i=j;i<=k;++i)
const int MAX = 2e5+111;
int vis[MAX];
vector <int> e[MAX];
int ans[MAX];
int cnt;
int sqrtn;
int dfs(int x){
int len = 0;
vis[x]=1;
for(int nxt:e[x]){
if(!vis[nxt]){
len = max(len,dfs(nxt));
}
}
if(len==sqrtn){
ans[++cnt] = x;
return 0;
}
if(!cnt && x==1) ans[++cnt] = 1;
++len;
return len;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin>>T;
while(T--){
int n,m,x,y;
cin>>n>>m;
sqrtn = sqrt(n);
if(n!=sqrtn*sqrtn) ++sqrtn;
FOR(i,1,m){
cin>>x>>y;
e[x].push_back(y);
e[y].push_back(x);
}
dfs(1);
cout<<cnt<<endl;
FOR(i,1,cnt) cout<<ans[i]<<' ';
cout<<endl;
cnt = 0;
FOR(i,1,n) ans[i]=0,vis[i]=0,e[i].clear();
}
return 0;
}
/*
1
5 4
1 2
3 2
4 2
5 2
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 8280kb
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:
1 2 1 1
result:
ok correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 18ms
memory: 8684kb
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:
3 11 6 1 1 1 1 2 1 1 1 1 2 6 2 1 1 1 4 2 10 3 1 1 3 15 9 3 1 3 1 2 1 5 1 1 3 11 6 1 1 1 1 1 1 2 1 1 1 2 1 3 1 4 2 5 1 1 1 3 11 6 1 1 1 2 5 1 1 1 1 1 3 16 10 4 1 2 1 4 2 7 4 1 1 1 3 1 2 1 3 3 7 6 1 1 1 2 8 3 1 1 1 3 1 2 1 1 2 6 1 1 3 1 3 2 5 1 1 1 3 1...
result:
wrong answer Condition failed: "getMaxBfsDist(n, subset) <= csqrtn" (test case 402)