QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#220811 | #6634. Central Subset | real_sigma_team | WA | 12ms | 8544kb | C++20 | 1.4kb | 2023-10-20 20:49:52 | 2023-10-20 20:49:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using ll = long long;
const int N = 2e5 + 5;
const int K = 449;
vector<int> gr[N];
int d[N], used[N];
const int inf = 1e9;
int k;
vector<int> ans;
void dfs(int v, int p) {
used[v] = 1;
int mx = 1e9;
for (int u: gr[v]) {
if (used[u] == 0){
dfs(u, v);
}
if(u != p)
mx = min(mx, d[u]);
}
if (mx == 1e9) {
d[v] = k;
}else{
if (mx + 1 >= k * 2) {
ans.push_back(v + 1);
} else {
if(v == 0 && sz(ans) == 0)
ans.push_back(v + 1);
d[v] = mx + 1;
}
}
}
void solve() {
int n, m;
cin >> n >> m;
k = ceil(sqrt(n));
{
ans.clear();
for (int i = 0; i < n; i++)
gr[i].clear(), used[i] = 0, d[i] = 0;
}
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u--, v--;
gr[u].push_back(v);
gr[v].push_back(u);
}
dfs(0,-1);
cout << sz(ans) << '\n';
for (int i: ans) {
cout << i << ' ';
}
cout << '\n';
}
int main() {
#ifndef LOCAL
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#else
freopen("input.txt", "r", stdin);
#endif
int t;
cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 8544kb
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 2 1 1
result:
ok correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 12ms
memory: 8148kb
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:
2 11 3 1 1 1 1 1 1 1 1 1 6 1 1 1 1 1 1 1 1 2 15 5 1 1 1 1 1 1 1 1 2 11 3 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 11 3 1 1 1 1 1 1 1 1 2 16 6 1 1 1 1 1 7 1 1 1 3 1 2 1 1 1 1 1 1 1 8 1 1 1 1 1 2 1 1 1 6 1 1 1 1 1 5 1 1 2 13 3 1 1 1 1 1 1 1 1 2 12 4 ...
result:
wrong answer Condition failed: "getMaxBfsDist(n, subset) <= csqrtn" (test case 3)