QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#135202 | #6634. Central Subset | wtn135687# | WA | 13ms | 9308kb | C++14 | 1.1kb | 2023-08-05 12:47:46 | 2023-08-05 12:47:47 |
Judging History
answer
#include<bits/stdc++.h>
#define pll pair<ll, ll>
using namespace std;
typedef long long ll;
#define int ll
const int N = 2e5+10;
const int M = 1e6 + 7;
int n, m, fa[N], mx;
vector<ll> edge[N], ans;
bool vis[N];
void init(){
for (int i = 0; i <= n; i++)fa[i] = i, edge[i].clear(),vis[i]=0;
ans.clear();
mx = sqrt(n);
if (mx * mx < n)mx++;
}
int dfs(int u,int dis){
if(dis>mx){
ans.push_back(u);
dis=0;
}
for(int v:edge[u]){
if(vis[v])continue;
vis[v]=1;
dis=min(dfs(v,dis+1),dis);
}
return dis+1;
}
inline void solve(){
cin >> n >> m;
init();
for (int i = 1, u, v; i <= m; i++){
cin >> u >> v;
edge[u].push_back(v);
edge[v].push_back(u);
}
// ans.push_back(1);
dfs(1,1);
if(ans.size()==0){
ans.push_back(1);
}
cout<<ans.size()<<"\n";for(int i:ans)cout<<i<<" ";cout<<"\n";
}
signed main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int WTN666=1;cin>>WTN666;
while(WTN666--){
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 9308kb
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 4 2 3 6
result:
ok correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 13ms
memory: 8700kb
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 5 10 15 2 6 5 1 9 1 1 1 1 2 4 8 1 1 2 11 8 2 6 16 1 1 3 6 12 18 1 4 1 5 1 10 1 1 3 5 10 15 2 7 6 1 1 2 5 7 1 1 1 3 1 4 2 11 14 2 12 11 1 1 3 5 10 15 2 4 6 2 12 15 1 1 1 1 3 6 12 18 2 12 13 1 5 2 9 15 1 1 1 4 1 4 1 10 2 7 17 1 1 2 5 10 2 6 5 1 5 2 1 4 1 1...
result:
wrong answer Condition failed: "getMaxBfsDist(n, subset) <= csqrtn" (test case 34)