QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#135279 | #6634. Central Subset | 4k2kok# | WA | 15ms | 75012kb | C++20 | 2.2kb | 2023-08-05 13:26:24 | 2023-08-05 13:26:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mem(a,b) memset((a),(b),sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
#define int long long
#define db long double
const double eps = 1e-6;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
int n, m, vis[maxn], len;
vector<int> dep[maxn];
vector<int> edge[maxn];
vector<int> e[maxn];
set<int> ans, temp;
void bfs(int u) {
queue<int> que;
que.push(u);
vis[u] = 1;
dep[1].push_back(u);
while(!que.empty()) {
int now = que.front();
que.pop();
for(int i = 0; i < edge[now].size(); i++) {
int v = edge[now][i];
if(vis[v] == 0) {
vis[v] = vis[now] + 1;
e[now].push_back(v);
e[v].push_back(now);
dep[vis[v]].push_back(v);
que.push(v);
}
}
}
}
void dfs(int now, int fa, int deep) {
if (deep % (2 * len + 1) == 0) {
ans.insert(now);
}
if (deep % (2 * len + 1) >= len && e[now].size() == 1 && now != 1) {
ans.insert(now);
return ;
}
for (auto chd : e[now]) {
if (chd == fa) continue;
dfs(chd, now, deep + 1);
}
}
void solve() {
ans.clear();
cin >> n >> m;
if(m == 0) {
cout << 1 << '\n';
cout << 1 << '\n';
return;
}
for(int i = 0; i <= n; i++) e[i].clear(), vis[i] = 0, edge[i].clear(), dep[i].clear();
for(int i = 0, u, v; i < m; i++) {
cin >> u >> v;
edge[u].push_back(v);
edge[v].push_back(u);
}
bfs(1);
// cerr << pos << '\n';
// for(int i = 1; i <= n; i++) {
// cerr << i << ": " << vis[i] << '\n';
// }
len = (int)ceil(sqrt(n));
dfs(1, -1, 0);
cout << ans.size() << '\n';
for (auto i : ans) {
cout << i << ' ';
}
cout << '\n';
}
signed main(){
io;
int T = 1;
cin >> T;
while(T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 6ms
memory: 75012kb
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 4 1 1
result:
ok correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 15ms
memory: 74172kb
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:
3 1 10 15 3 1 5 6 4 1 6 9 10 1 1 1 1 2 1 8 1 1 6 1 8 11 12 13 14 7 1 5 7 8 11 13 16 1 1 3 1 12 20 4 1 5 7 8 4 1 6 9 10 7 1 9 11 12 14 16 17 1 1 3 1 10 15 4 1 5 6 7 1 1 5 1 5 7 8 9 1 1 2 1 4 3 1 7 8 6 1 8 11 12 13 14 6 1 12 13 15 16 18 1 1 3 1 10 15 3 1 4 6 7 1 9 12 13 14 1...
result:
wrong answer Integer 6 violates the range [1, 4] (test case 8)