QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#579763 | #6634. Central Subset | Golden | WA | 15ms | 5744kb | C++23 | 4.5kb | 2024-09-21 17:45:42 | 2024-09-21 17:45:43 |
Judging History
answer
#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
//#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define DEBUG
#define x first
#define y second
#define pb push_back
#define all(a) a.begin(),a.end()
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<pii> vii;
typedef vector<pll> vll;
template<class T> bool umin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool umax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnd(time(nullptr));
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(ll x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(ull x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(ld x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef DEBUG
#define dbg(x...) cerr << __func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << endl;
#else
#define dbg(x...)
#endif
const int N = 2e5 + 5, inf = 1e9;
vi g[N];
int dist[N], n, sq;
int pr[N];
bool used[N];
void bfs(int *d, int s) {
for (int i = 1; i <= n; ++i) {
used[i] = false;
d[i] = inf;
}
used[s] = true;
d[s] = 0;
pr[s] = -1;
queue<int> q;
q.push(s);
while (!q.empty()) {
int cur = q.front();
q.pop();
for (int to : g[cur]) {
if (!used[to]) {
used[to] = true;
dist[to] = dist[cur] + 1;
pr[to] = cur;
q.push(to);
}
}
}
}
void solve() {
int m; cin >> n >> m;
sq = 1;
while (sq * sq < n) sq++;
for (int i = 1; i <= n; ++i) {
g[i].clear();
}
for (int i = 1; i <= m; ++i) {
int u, v; cin >> u >> v;
g[u].pb(v), g[v].pb(u);
}
bfs(dist, 1);
int st = 1;
for (int i = 1; i <= n; ++i) {
if (dist[i] > dist[st]) {
st = i;
}
}
// cout << "diam: " << st << " ";
bfs(dist, st);
st = 1;
for (int i = 1; i <= n; ++i) {
if (dist[i] > dist[st]) {
st = i;
}
}
// cout << st << " ";
int cnt = dist[st];
while (dist[st] != cnt / 2) {
st = pr[st];
}
// cout << st << "\n";
for (int i = 1; i <= n; ++i) {
used[i] = false;
dist[i] = inf;
}
used[st] = true;
dist[st] = 0;
queue<int> q;
q.push(st);
vi ans;
ans.pb(st);
while (!q.empty()) {
int cur = q.front();
q.pop();
for (int to : g[cur]) {
if (!used[to]) {
used[to] = true;
dist[to] = dist[cur] + 1;
if (dist[to] % (sq + 1) == 0) {
ans.pb(to);
}
q.push(to);
}
}
}
if (ans.size() > sq) {
cout << "-1\n";
}
else {
cout << ans.size() << "\n";
for (int v : ans) {
cout << v << " ";
}
cout << "\n";
}
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t; cin >> t;
while (t--) solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3688kb
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 3 1 4
result:
ok correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 15ms
memory: 5744kb
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 8 13 3 1 2 1 4 1 2 1 2 3 5 1 9 1 2 1 5 2 10 1 1 2 3 11 17 5 1 4 1 4 1 8 1 2 3 8 3 13 1 2 1 2 1 4 1 2 1 3 1 4 1 5 1 8 1 2 3 8 13 3 1 2 1 5 1 2 1 2 3 11 5 17 1 3 1 5 2 7 5 1 2 1 4 1 3 1 4 3 5 21 20 1 2 3 7 12 2 1 2 1 4 1 3 1 2 2 6 1 1 6 1 4 1 7 1 2 3...
result:
wrong answer Integer -1 violates the range [1, 4] (test case 799)