QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#174129 | #6634. Central Subset | Klaus26# | WA | 11ms | 8552kb | C++20 | 1.0kb | 2023-09-10 04:28:53 | 2023-09-10 04:28:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "../debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
const int N = 2e5+10;
vector<int> g[N];
int vis[N];
int n, m, lim;
void cl(){
for(int i=1; i<=n; i++){
g[i].clear();
vis[i] = 0;
}
}
void dfs(int u, int dis){
if(dis > lim) return;
vis[u] = 1;
for(auto& v : g[u]){
if(vis[v])continue;
dfs(v,dis+1);
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int T;
cin>>T;
while(T--){
cin>>n>>m;
lim = sqrt(n);
while(true){
if(lim * lim >= n )break;
lim++;
}
debug(lim);
for(int i=0; i<m; i++){
int u, v;
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
vector<int> ans;
for(int i=1; i<=n; i++){
if(vis[i])continue;
ans.push_back(i);
dfs(i,0);
}
cout<<ans.size()<<'\n';
for(auto& i : ans) cout<<i<<' ';
cout<<'\n';
cl();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 8320kb
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 1 1
result:
ok correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 11ms
memory: 8552kb
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 1 6 11 1 1 3 1 6 10 1 1 1 1 3 1 5 9 1 1 3 1 6 12 5 1 7 8 9 10 1 1 4 1 7 13 19 3 1 6 7 3 1 6 10 4 1 11 12 13 1 1 3 1 6 11 1 1 1 1 2 1 9 1 1 2 1 4 2 1 6 3 1 6 12 3 1 13 14 1 1 3 1 6 11 1 1 3 1 6 13 1 1 1 1 4 1 7 13 19 4 1 9 11 13 3 1 6 12 3 1 10 11 1 1 2 1 5 3 1 6...
result:
wrong answer Integer 5 violates the range [1, 4] (test case 9)