QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#207896 | #6634. Central Subset | UFRJ# | WA | 32ms | 3812kb | C++20 | 1.5kb | 2023-10-08 22:09:48 | 2023-10-08 22:09:48 |
Judging History
answer
#include<bits/stdc++.h>
int main() {
using namespace std;
cin.tie(nullptr)->sync_with_stdio(false);
int T; cin >> T;
while (T--) {
int N, M; cin >> N >> M;
vector<vector<int>> adj(N);
for (int i = 0; i < M; ++i) {
int a, b; cin >> a >> b;
--a, --b;
adj[a].push_back(b);
adj[b].push_back(a);
}
cerr << endl;
vector<vector<int>> tree(N);
vector<bool> vis(N); vis[0] = true;
vector<int> bfs = {0}; bfs.reserve(N);
for (int z = 0; z < int(bfs.size()); ++z) {
int cur = bfs[z];
for (int nxt : adj[cur]) {
if (vis[nxt]) continue;
vis[nxt] = true;
// cerr << cur << ' ' << nxt << endl;
tree[cur].push_back(nxt);
tree[nxt].push_back(cur);
bfs.push_back(nxt);
}
}
int sqn = 1;
while (sqn * sqn <= N) sqn += 1;
// cerr << "sqrt " << sqn << endl;
vector<int> depth(N); depth[0] = 1;
auto dfs = [&](auto&& self, int cur) -> void {
for (int nxt : tree[cur]) {
if (depth[nxt]) continue;
depth[nxt] = depth[cur] + 1;
self(self, nxt);
}
};
dfs(dfs, 0);
/*
for (int i = 0; i < N; ++i) {
cerr << depth[i] << endl;
}
*/
vector<vector<int>> loc(sqn, {0});
for (int i = 0; i < N; ++i) {
loc[depth[i] % sqn].push_back(i);
}
for (int i = 0; i < sqn; ++i) {
int s = int(loc[i].size());
if (s <= sqn) {
cout << s << '\n';
for (int j = 0; j < s; ++j) {
cout << loc[i][j] + 1 << " \n"[j == s-1];
}
break;
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
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 3 3 1 5 6
result:
ok correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 32ms
memory: 3704kb
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:
4 1 4 8 12 3 1 3 4 3 1 4 8 2 1 2 2 1 2 3 1 4 8 2 1 2 4 1 1 5 11 4 1 5 6 16 1 1 5 1 5 10 15 20 3 1 3 8 3 1 4 8 4 1 6 7 8 2 1 1 4 1 4 8 12 3 1 3 4 2 1 2 3 1 1 9 1 1 2 1 3 3 1 2 6 4 1 1 5 11 5 1 7 8 9 10 2 1 1 4 1 4 8 12 3 1 3 5 3 1 5 12 2 1 2 2 1 1 5 1 5 10 15 20 3 1 5 8 4 1 1 5 11 4 1 7 8 9 2 1 1 3 1...
result:
wrong answer Condition failed: "subset.size() == sz" (test case 8)