QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#214478 | #6634. Central Subset | bronze_RE | WA | 21ms | 144088kb | C++20 | 1.4kb | 2023-10-14 20:02:43 | 2023-10-14 20:02:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
const int N = 3e6 + 9;
int n,m;
vector<int>node[N], E[N], ans;
bool vis[N];
int dep[N], fa[N];
int limit;
void dfs(int u, int f){
vis[u] = 1;
fa[u] = f;
for(int i = 0;i < (int)node[u].size() ;i++){
int v = node[u][i];
if(vis[v] == true) continue;
dfs(v, u);
}
}
void DFS(int u ,int f){
for(int i = 0;i < E[u].size(); i++){
int v = E[u][i];
if(v == f) continue;
DFS(v, u) ;
dep[u] == max(dep[u], dep[v] + 1);
}
if(dep[u] >= limit || u == 1){
dep[u] = 0;
ans.emplace_back(u);
}
}
void solve(){
cin>> n >> m;
limit = ceil(sqrt(n)); ans.clear();
for(int i = 1;i <= m;i++) {
int u, v ;cin >> u >> v;
node[u].push_back(v) ;
node[v].push_back(u);
}
dfs(1, 1) ;
for(int i = 1;i <= n;i++){
E[fa[i]].push_back(i);
}
DFS(1 , 1);
cout << ans.size() <<endl;
for(auto v : ans) cout << v <<" ";
cout <<endl;
for(int i = 1;i <= n;i++) {
node[i].clear() ,E[i].clear();
dep[i] = 0 ,vis[i] = 0;
}
return ;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int _;
cin >> _;
while( _ -- ) solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 21ms
memory: 144088kb
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 1 1 1
result:
wrong answer Condition failed: "getMaxBfsDist(n, subset) <= csqrtn" (test case 1)