QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#579824 | #6634. Central Subset | llg | WA | 19ms | 6192kb | C++14 | 2.3kb | 2024-09-21 18:15:45 | 2024-09-21 18:15:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define mod 1000000007
const int N = 1e5 + 7;
int mx;
int n;
vector<int> answer;
vector<int> adj[N];
void construct_bfs_tree(vector<vector<int>> &tree)
{
queue<int> q;
q.push(1);
vector<bool> vis(n, false);
vis[1] = true;
while (!q.empty())
{
int node = q.front();
q.pop();
for (auto it : adj[node])
{
if (!vis[it])
{
tree[node].push_back(it);
tree[it].push_back(node);
vis[it] = true;
q.push(it);
}
}
}
}
void dfs(int node, int par, int distance, vector<vector<int>> &tree)
{
if (distance > mx)
{
answer.push_back(node);
distance = 0;
}
for (auto it : tree[node])
{
if (it != par)
{
dfs(it, node, distance + 1, tree);
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("a.in", "r", stdin);
freopen("a.out", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
answer.clear();
cin >> n;
int m;
cin >> m;
mx = (int)ceil(sqrt(n));
for (int i = 1; i <= n; i++)
{
adj[i].clear();
}
for (int i = 1; i <= m; i++)
{
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
vector<vector<int>> tree(n + 1);
construct_bfs_tree(tree);
// for (int u = 1; u <= n; u++)
// {
// for (int v : tree[u])
// {
// if (v < u)
// continue;
// cout << u << " " << v << endl;
// }
// }
dfs(1, 0, 0, tree);
answer.push_back(1);
cout << (int)answer.size() << endl;
for (int a : answer)
{
cout << a << " ";
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 6176kb
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 4 1 1 1
result:
ok correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 19ms
memory: 6192kb
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 6 11 1 1 1 3 6 10 1 1 1 1 1 3 5 9 1 1 1 3 6 12 1 5 10 9 8 7 1 1 1 4 7 13 19 1 3 6 7 1 3 10 6 1 4 13 12 11 1 1 1 3 6 11 1 1 1 1 1 2 9 1 1 1 2 4 1 2 6 1 3 6 12 1 3 13 14 1 1 1 3 6 11 1 1 1 3 6 13 1 1 1 1 1 4 7 13 19 1 4 11 13 9 1 3 6 12 1 3 11 10 1 1 1 2 5 1 3 6 7 1 3 6 11 1 3 10 9 1 1 1 3 6 11 1 1 ...
result:
wrong answer Integer 5 violates the range [1, 4] (test case 9)