#include "Joi.h"
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <functional>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
struct UF {
int N;
vector<int> U, R;
UF(int N) : N(N), U(N), R(N, 1) {
rep(i, N) U[i] = i;
}
int find(int x) {
if (U[x] == x) return x;
return U[x] = find(U[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y) return;
if (R[x] < R[y]) swap(x, y);
U[y] = x;
R[x] += R[y];
}
bool same(int x, int y) {
return find(x) == find(y);
}
};
void Joi(int N, int M, int GA[], int GB[], long long X, int T) {
int A[10000] = {};
vector<int> G[10000];
int deg[10000] = {};
set<int> S[10000], leaf[10000];
UF uf(N);
rep(i, M) {
int a = GA[i], b = GB[i];
if (!uf.same(a, b)) {
G[a].pb(b), G[b].pb(a);
uf.unite(a, b);
}
}
rep(i, N) A[i] = -1, sort(all(G[i]));
set<int> used, lf;
queue<P> q;
q.push(P(0, -1));
rep(i, 60) {
int x = q.front()._1, p = q.front()._2; q.pop();
A[x] = i;
used.insert(x);
if (p != -1) deg[x]++, deg[p]++;
for (int t : G[x]) if (t != p) q.push(P(t, x));
}
rep(i, N) if (deg[i] == 1) lf.insert(i);
for (int x : used) S[x] = used, leaf[x] = lf;
while (!q.empty()) {
int x = q.front()._1, p = q.front()._2; q.pop();
S[x] = set<int>(S[p]);
S[x].insert(x);
leaf[x] = set<int>(leaf[p]);
if (leaf[x].find(p) != leaf[x].end()) leaf[x].erase(p);
assert(!leaf[x].empty());
int from = *leaf[x].begin();
leaf[x].erase(from);
S[x].erase(from);
int ch = -1;
for (int x : G[from]) if (S[x].find(x) != S[x].end()) ch = x;
int deg = 0;
for (int t : S[x]) if (binary_search(all(G[t]), ch)) deg++;
if (deg == 1) leaf[x].insert(ch);
A[x] = A[from];
leaf[x].insert(x);
for (int t : G[x]) if (t != p) q.push(P(t, x));
}
rep(i, N) assert(S[i].size() == 60);
rep(i, N) MessageBoard(i, (X>>A[i])&1);
}
#include "Ioi.h"
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <functional>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
struct UF {
int N;
vector<int> U, R;
UF(int N) : N(N), U(N), R(N, 1) {
rep(i, N) U[i] = i;
}
int find(int x) {
if (U[x] == x) return x;
return U[x] = find(U[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y) return;
if (R[x] < R[y]) swap(x, y);
U[y] = x;
R[x] += R[y];
}
bool same(int x, int y) {
return find(x) == find(y);
}
};
long long Ioi(int N, int M, int GA[], int GB[], int start, int V, int T) {
int A[10000] = {};
vector<int> G[10000];
int deg[10000] = {};
set<int> S[10000], leaf[10000];
UF uf(N);
rep(i, M) {
int a = GA[i], b = GB[i];
if (!uf.same(a, b)) {
G[a].pb(b), G[b].pb(a);
uf.unite(a, b);
}
}
rep(i, N) A[i] = -1, sort(all(G[i]));
set<int> used, lf;
queue<P> q;
q.push(P(0, -1));
rep(i, 60) {
int x = q.front()._1, p = q.front()._2; q.pop();
A[x] = i;
used.insert(x);
if (p != -1) deg[x]++, deg[p]++;
for (int t : G[x]) if (t != p) q.push(P(t, x));
}
rep(i, N) if (deg[i] == 1) lf.insert(i);
for (int x : used) S[x] = used, leaf[x] = lf;
while (!q.empty()) {
int x = q.front()._1, p = q.front()._2; q.pop();
S[x] = set<int>(S[p]);
S[x].insert(x);
leaf[x] = set<int>(leaf[p]);
if (leaf[x].find(p) != leaf[x].end()) leaf[x].erase(p);
assert(!leaf[x].empty());
int from = *leaf[x].begin();
leaf[x].erase(from);
S[x].erase(from);
int ch = -1;
for (int x : G[from]) if (S[x].find(x) != S[x].end()) ch = x;
int deg = 0;
for (int t : S[x]) if (binary_search(all(G[t]), ch)) deg++;
if (deg == 1) leaf[x].insert(ch);
A[x] = A[from];
leaf[x].insert(x);
for (int t : G[x]) if (t != p) q.push(P(t, x));
}
rep(i, N) assert(S[i].size() == 60);
bool ok[10000] = {};
for (int t : S[start]) ok[t] = true;
long long X = 0;
function<void(int, int, int)> dfs = [&](int x, int p, int v) {
X |= ((long long)v)<<A[x];
for (int t : G[x]) if (t != p && ok[t]) {
dfs(t, x, Move(t));
Move(x);
}
};
dfs(start, -1, V);
return X;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
7556 KB |
Output is correct |
2 |
Correct |
6 ms |
8356 KB |
Output is correct |
3 |
Correct |
3 ms |
9940 KB |
Output is correct |
4 |
Runtime error |
0 ms |
3788 KB |
Execution killed because of forbidden syscall gettid (186) |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
39 ms |
23880 KB |
Execution killed because of forbidden syscall gettid (186) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
7572 KB |
Output is correct |
2 |
Correct |
3 ms |
7576 KB |
Output is correct |
3 |
Correct |
0 ms |
7564 KB |
Output is correct |
4 |
Correct |
18 ms |
16544 KB |
Output is correct |
5 |
Correct |
18 ms |
16540 KB |
Output is correct |
6 |
Correct |
22 ms |
16536 KB |
Output is correct |
7 |
Correct |
18 ms |
16544 KB |
Output is correct |
8 |
Correct |
18 ms |
16540 KB |
Output is correct |
9 |
Correct |
185 ms |
65164 KB |
Output is correct |
10 |
Correct |
182 ms |
65160 KB |
Output is correct |
11 |
Correct |
164 ms |
65164 KB |
Output is correct |
12 |
Correct |
0 ms |
7568 KB |
Output is correct |
13 |
Correct |
0 ms |
7564 KB |
Output is correct |
14 |
Correct |
0 ms |
7304 KB |
Output is correct |
15 |
Correct |
0 ms |
7304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
43 ms |
20840 KB |
Execution killed because of forbidden syscall gettid (186) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
9088 KB |
Execution killed because of forbidden syscall gettid (186) |
2 |
Halted |
0 ms |
0 KB |
- |