QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#518056 | #6634. Central Subset | Cleshm | WA | 15ms | 16376kb | C++14 | 3.6kb | 2024-08-13 15:20:05 | 2024-08-13 15:20:05 |
Judging History
answer
#include "bits/stdc++.h"
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define OPEN freopen ("set.in", "r", stdin); freopen ("set.out", "w", stdout);
#define pc __builtin_popcount
#define db double
#define pii pair<int, int>
#define fi first
#define se second
#define F(i,x,y) for (int i = (x); i <= (y); ++i)
#define D(i,x,y) for (int i = (x); i >= (y); --i)
using namespace std;
const ll inf = 1ll * 1e18;
//const ll mod = 998244353ll;
const ll mod = 1ll * 1e9 + 7ll;
inline void Rd(int& x) {
int f = 1;
x = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c - 48), c = getchar();
x *= f;
}
inline void Wt(int x) {
if (x < 10) {
putchar(x + 48);
return;
}
Wt(x / 10);
putchar((x % 10) + 48);
}
int n, m;
struct Dsu {
int f[310000];
void Init() {
F(i, 1, n) f[i] = i;
}
int Find (int x) {
if (x == f[x]) return x;
return f[x] = Find(f[x]);
}
void U (int x, int y) {
int tx = Find(x), ty = Find(y);
f[tx] = ty;
}
} w;
struct Node {
int dep, id;
vector<int> v;
bool operator <(const Node& p) const {
return dep > p.dep;
}
} t[310000];
struct Ds {
int id, dis;
};
void Dfs(int now, int dp) {
t[now].dep = dp;
// if(now%20000==0)cerr<<now<<':'<<(double)clock() / CLOCKS_PER_SEC<<'\n';
for (auto i : t[now].v) {
if (! t[i].dep) {
Dfs (i, dp + 1);
}
}
}
queue<Ds> q;
vector<int> ans;
int dis[310000];
int vis[310000];
int nid[310000];
void Main() {
// OPEN
IOS
cin >> n >> m;
w.Init();
// cerr<<(double)clock() / CLOCKS_PER_SEC<<'\n';
F(i, 1, m) {
int x, y;
cin >> x >> y;
// if(i%100000==0)cerr<<(double)clock() / CLOCKS_PER_SEC<<'\n';
int tx = w.Find(x), ty = w.Find(y);
// cerr <<x<<' '<<y<<' '<<tx<<' '<<ty<<'\n';
if (tx != ty) {
w.U(x, y);
t[x].v.push_back(y);
t[y].v.push_back(x);
}
}
// cerr<<(double)clock() / CLOCKS_PER_SEC<<'\n';
// F(i, 1, n) {
// cerr<<i<<':';
// for (auto j : t[i].v) cerr << j << ' ';
// cerr << '\n';
// }
Dfs(1, 1);
// cerr<<(double)clock() / CLOCKS_PER_SEC<<'\n';
F(i, 1, n) t[i].id = i;
// F(i, 1, n) cerr << t[i].dep << '\n';
sort (t + 1, t + n + 1);
F(i, 1, n) nid[t[i].id] = i;
int k = 0;
for(int i = 1; ; ++ i) {
if (i * i >= n) {
k = i;
break;
}
}
int nxt = -1;
F(i, 1, n) dis[i] = 0x3f3f3f3f;
// cerr<<(double)clock() / CLOCKS_PER_SEC<<'\n';
F(i, 1, n) {
// cerr<<nxt<<'\n';
// F(j,1,n)cerr<<dis[j]<<' ';
// cerr<<'\n';
if (nxt != -1 && t[i].dep == nxt) {
Ds u, to;
// cerr<<"w"<<t[i].id <<'\n';
u.dis = 0, u.id = t[i].id;
q.push(u);
F(j, 1, n) vis[j] = 0;
while (! q.empty()) {
u = q.front();
q.pop();
// cerr<<u.id<<':';
for (auto j : t[nid[u.id]].v) {
// cerr<<j<<' ';
to.id = j, to.dis = u.dis + 1;
if (! vis[to.id]) {
vis[to.id] = 1;
dis[to.id] = min(dis[to.id], to.dis);
q.push(to);
}
}
// cerr<<'\n';
}
ans.push_back(t[i].id);
nxt = -1;
}
if (dis[i] > k && nxt == -1) {
// cerr<<t[i].dep<<' '<<k<<'\n';
nxt = max(t[i].dep - k, 1);
}
// cerr<<nxt<<'\n';
// F(j,1,n)cerr<<dis[j]<<' ';
// cerr<<'\n';
}
// F(i, 1, n) cerr <<dis[i] << ' ';
cout << ans.size() << '\n';
for (auto i : ans) cout << i << ' '; cout << '\n';
F(i, 1, n) t[i].v.clear();
F(i, 1, n) t[i].dep = 0;
ans.clear();
}
int main() {
int T; cin >> T; while (T --) Main();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 16376kb
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 2 1 1
result:
ok correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 15ms
memory: 15932kb
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:
2 11 7 1 1 1 2 1 1 1 1 1 6 1 1 1 4 2 7 1 1 1 2 15 10 1 3 1 2 1 5 1 1 2 11 7 1 1 1 1 1 2 1 1 1 2 1 3 1 4 2 6 1 1 1 2 11 7 1 1 1 5 1 1 1 1 2 16 11 1 2 1 4 1 7 1 1 1 3 1 2 1 3 2 8 1 1 1 1 8 1 1 1 3 1 2 1 1 1 6 1 3 1 3 2 4 1 1 1 2 13 8 1 1 1 3 2 3 1 ...
result:
wrong answer Condition failed: "getMaxBfsDist(n, subset) <= csqrtn" (test case 1)