QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#134921#6634. Central SubsetRd_rainydays#RE 3ms8384kbC++20870b2023-08-05 10:02:292023-08-05 10:02:31

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-05 10:02:31]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:8384kb
  • [2023-08-05 10:02:29]
  • 提交

answer

#include <bits/stdc++.h>

const int N = 2e5 + 5;
std::vector<int> g[N];
int n, m, dep[N];
bool vis[N];

void solve() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) g[i].clear();

  for (int u, v, i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }

  memset(vis + 1, 0, n * sizeof(bool));
  auto dfs = [&](int x, int f, auto &dfs) -> void {
    if (vis[x]) return;
    vis[x] = 1, dep[x] = dep[f] + 1;
    for (auto y : g[x]) dfs(y, x, dfs);
  };
  dfs(1, 0, dfs);

  int t = ceil(sqrt(n));
  std::vector<int> S;
  for (int i = 1; i <= n; i++) {
    if ((dep[i] - 1) % t == 0) S.push_back(i);
  }

  assert(S.size() <= t);
  printf("%u\n", S.size());
  for (auto x : S) printf("%d ", x);
  puts("");
}

signed main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 8384kb

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 
2
1 6 

result:

ok correct (2 test cases)

Test #2:

score: -100
Dangerous Syscalls

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:


result: