QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#139608 | #6634. Central Subset | FzArK | WA | 2ms | 9372kb | C++17 | 2.4kb | 2023-08-14 03:39:17 | 2023-08-14 03:39:18 |
Judging History
answer
#include<bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sc(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define clr(x) vector<int>().swap(x);
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define endl '\n'
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define popf pop_front
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define random mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define S second
const ll INF=1e18;
const ll MN=-2e9;
const ll MX=2e5+9;
const ll MXX=1e9;
const ll SQ=4e2;
const ll MOD=998244353;
const ll PP=1e6+3;
const ld PI=3.141592653589793;
const ld eps=1e-11;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;
int n, m, q, p[MX], d[MX], vis[MX];
vector<int> I, ans, adj[MX];
void init() {
q = 0;
I.clear();
ans.clear();
for (int i=1; i<=n; i++) {
vis[i] = 0;
adj[i].clear();
}
}
void go(int u, int par) {
if (vis[u]) return;
vis[u] = 1;
p[u] = par;
d[u] = d[par] + 1;
for (auto v:adj[u]) go(v, u);
vis[u] = 0;
}
void gg(int u) {
if (vis[u]) return;
vis[u] = 1;
for (auto v:adj[u]) if (v != p[u]) {
gg(v);
}
}
void solve() {
cin >> n >> m;
while (m--) {
int u, v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
go(1, 0);
for (int i=1; i<=n; i++) I.pb(i);
// while (q*q < n) q++;
sort (all(I), [&](int i, int j){
if (d[i] == d[j]) return i < j;
return d[i] > d[j];
});
for (auto v:I) if (!vis[v]) {
for (int i=0; i<10; i++) {
if (v == 1) break;
v = p[v];
}
if (vis[v]) continue;
gg(v);
ans.pb(v);
}
cout << sz(ans) << endl;
for (auto x:ans) cout << x << " "; cout << endl;
init();
}
int main() {
FAST;
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
/*
*/
详细
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 9372kb
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 1 1 1
result:
wrong answer Condition failed: "getMaxBfsDist(n, subset) <= csqrtn" (test case 1)