QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#136446#6634. Central SubsetNightW0lf#WA 6ms17408kbC++232.3kb2023-08-08 19:33:492023-08-08 19:33:51

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-08 19:33:51]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:17408kb
  • [2023-08-08 19:33:49]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
#define int long long
#define ll long long 
#define lll __int128_t
#define pb push_back
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;
vector<int> adj[200005];
vector<int> adj_tree[200005];

vector<int> rem(200005);
vector<int> vis(200005);
vector<int> level(200005);
void dfs(int root, int par) {
    vis[root] = 1;
    for(auto x: adj[root]) {
        if(vis[x]) continue;
        adj_tree[root].push_back(x);
        adj_tree[x].push_back(root);
        dfs(x, root);
    }
}
int lim;
vector<int> ans;
void dfs_depth(int root) {
    vis[root] = 1;
    level[root] = 0;
    for(auto x: adj_tree[root]) {
        if(vis[x] == 0 and rem[x] == 0) {
            vis[x] = 1;
            dfs_depth(x);
            level[root] = max(level[root], level[x] + 1);
        }
    }
    if(level[root] == lim) {
        ans.push_back(root);
        level[root] = -1;
        rem[root] = 1;
    }
}



void solve() {
    int n, m; cin >> n >> m;
    ans.clear();
    for(int i = 1; i <= n; i++) adj[i].clear(), adj_tree[i].clear(), vis[i] = 0, level[i] = 0, rem[i] = 0;
    //vector<multiset<int>> adj(n + 1);
    int lim = sqrt(n);
    if(lim * lim != n) lim++;
    for(int i = 1; i <= m; i++) {
        int u, v; cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    dfs(1, 0);

    dfs_depth(1);

    if(!rem[1]) ans.push_back(1);

    assert(ans.size() <= lim);

    cout << ans.size() << "\n";
    for(auto x: ans) cout << x << " ";
    cout << "\n";

}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t; cin >> t;
    while(t--) {
        solve();
    }
}

详细

Test #1:

score: 0
Wrong Answer
time: 6ms
memory: 17408kb

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)