QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214478#6634. Central Subsetbronze_REWA 21ms144088kbC++201.4kb2023-10-14 20:02:432023-10-14 20:02:43

Judging History

你现在查看的是最新测评结果

  • [2023-10-14 20:02:43]
  • 评测
  • 测评结果:WA
  • 用时:21ms
  • 内存:144088kb
  • [2023-10-14 20:02:43]
  • 提交

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)