QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#593227 | #6634. Central Subset | Kandarp08 | RE | 0ms | 3596kb | C++20 | 3.1kb | 2024-09-27 12:47:17 | 2024-09-27 12:47:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define HASH_MOD1 998244353
#define HASH_MOD2 1000000009
#define HASH 31
#define ll long long
#define int long long
typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;
template <typename T>
istream& operator>> (istream& in, vector<T>& a)
{
for (int i = 0; i < a.size(); ++i)
in >> a[i];
return in;
}
template <typename T>
ostream& operator<< (ostream& out, vector<T>& a)
{
for (int i = 0; i < a.size(); ++i)
out << a[i] << " ";
out << "\n";
return out;
}
template <typename T>
ostream& operator<< (ostream& out, set<T>& s)
{
for (int x : s)
out << x << " ";
out << "\n";
return out;
}
template <typename T>
ostream& operator<< (ostream& out, vector<pair<T, T>>& v)
{
for (int i = 0; i < v.size(); ++i)
out << v[i].first << " " << v[i].second << "\n";
return out;
}
ll modinv(ll a)
{
return a <= 1 ? a : MOD - (MOD / a) * modinv(MOD % a) % MOD;
}
ll binpow(ll x, ll y)
{
ll ans = 1;
while (y > 0)
{
if (y % 2 == 1)
ans *= x;
x = x * x;
y = y / 2;
x %= MOD;
ans %= MOD;
}
return ans;
}
void init(vector<int> adj[], vector<int> children[], bool visited[], int u)
{
visited[u] = true;
for (int v : adj[u])
{
if (!visited[v])
{
children[u].push_back(v);
init(adj, children, visited, v);
}
}
}
int dfs(vector<int> children[], vector<int>& taken, int u, int d, int sq)
{
int mx_depth = d;
//cout << "u = " << u << " depth = " << d << "\n";
for (int v : children[u])
{
int res = dfs(children, taken, v, d + 1, sq);
//cout << "u = " << u << " v = " << v << " res = " << res << "\n";
if (res == -1)
continue;
if (res - d == sq)
{
taken.push_back(u);
return -1;
}
mx_depth = max(mx_depth, res);
}
return mx_depth;
}
void solve()
{
int n, m, i;
cin >> n >> m;
vector<int> adj[n], children[n];
bool visited[n] = {false};
for (i = 0; i < m; ++i)
{
int u, v;
cin >> u >> v;
adj[u - 1].push_back(v - 1);
adj[v - 1].push_back(u - 1);
}
init(adj, children, visited, 0);
vector<int> taken;
int sq = (int)ceil(sqrt(n));
dfs(children, taken, 0, 0, sq);
if (taken.size() < sq && taken.back() != 0)
taken.push_back(0);
cout << taken.size() << "\n";
for (i = 0; i < taken.size(); ++i)
cout << taken[i] + 1 << " ";
cout << "\n";
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
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 2 1 1 1
result:
ok correct (2 test cases)
Test #2:
score: -100
Runtime Error
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 ...