#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4+1;
void dfs(int u, vector<vector<int> > &g, vector<int> &pre, int &tick) {
pre[u] = ++tick;
for(int v: g[u]) {
if(pre[v]) continue;
dfs(v, g, pre, tick);
}
}
void Joi(int n, int m, int A[], int B[], long long X, int T) {
vector<vector<int> > g(n + 1);
vector<int> pre(n + 1);
int tick = 0;
for(int i = 0; i < m; i++) {
g[A[i]].push_back(B[i]);
g[B[i]].push_back(A[i]);
}
dfs(0, g, pre, tick);
for(int i = 0; i < n; i++) {
MessageBoard(i, X >> ((pre[i] - 1) % 60) & 1);
}
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4+1;
void dfs(int u, vector<vector<int> > &g, vector<int> &d, vector<int> &par, vector<int> &pre, vector<int>& rev, int &tick) {
pre[u] = ++tick;
for(int v: g[u]) {
if(pre[v]) continue;
d[v] = d[u] + 1;
par[v] = u;
dfs(v, g, d, par, pre, rev, tick);
}
// cerr << u << ' ' << pre[u] << endl;
}
int get_lca(int u, int v, vector<int> &d, vector<int> &par) {
if(d[u] < d[v]) swap(u, v);
while(d[u] > d[v]) u = par[u];
while(u != v) {
u = par[u];
v = par[v];
}
return u;
}
long long moveToNext(int u, int v, vector<int> &d, vector<int> &par) {
int lca = get_lca(u, v, d, par);
// cerr << "Ioi_moveToNext " << u <<' ' << v << ' ' << lca << endl;
vector<int> ord1, ord2;
while(u != lca) {
ord1.push_back(u);
u = par[u];
}
while(v != lca) {
ord2.push_back(v);
v = par[v];
}
vector<int> ord = ord1;
ord.push_back(lca);
for(int i = ord2.size() - 1; i >= 0; i--) ord.push_back(ord2[i]);
ord.erase(ord.begin());
// for(int x: ord) cerr << x << ' ';
// cerr << endl;
int ret = -1;
for(int x: ord) ret = Move(x);
return ret;
}
long long Ioi(int n, int m, int A[], int B[], int P, int V, int T) {
vector<vector<int> > g(n + 1);
vector<int> d(n + 1), par(n + 1), pre(n + 1), rev(n + 1);
int tick = 0;
for(int i = 0; i < m; i++) {
g[A[i]].push_back(B[i]);
g[B[i]].push_back(A[i]);
}
dfs(0, g, d, par, pre, rev, tick);
for(int i = 0; i < n; i++) {
--pre[i];
rev[pre[i]] = i;
// cerr << "Ioi_pre " << i << ' ' << pre[i] << endl;
}
// for(int i = 0; i < n; i++) {
// cerr << "Ioi_rev " << i << ' ' << rev[i] << endl;
// }
long long ret = V << pre[P] % 60;
int curr = P;
for(int step = 1; step < 60; step++) {
int pos = (pre[P] + step) % 60;
int nxt = rev[pre[P] + step < n ? pre[P] + step : (pre[P] + step) % 60];
assert(0 <= curr && curr < n && 0 <= nxt && nxt < n && curr != nxt);
// cerr << "Ioi_iterate " << curr << ' ' << nxt << ' ' << pos << endl;
ret += moveToNext(curr, nxt, d, par) << pos;
curr = nxt;
}
return ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
856 KB |
Output is correct |
2 |
Correct |
4 ms |
772 KB |
Output is correct |
3 |
Correct |
5 ms |
904 KB |
Output is correct |
4 |
Correct |
5 ms |
772 KB |
Output is correct |
5 |
Correct |
6 ms |
764 KB |
Output is correct |
6 |
Correct |
5 ms |
852 KB |
Output is correct |
7 |
Correct |
5 ms |
992 KB |
Output is correct |
8 |
Correct |
5 ms |
904 KB |
Output is correct |
9 |
Incorrect |
5 ms |
904 KB |
Wrong Answer [7] |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
4328 KB |
Output is correct |
2 |
Correct |
31 ms |
4688 KB |
Output is correct |
3 |
Incorrect |
32 ms |
4648 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Correct |
5 ms |
752 KB |
Output is correct |
3 |
Correct |
5 ms |
900 KB |
Output is correct |
4 |
Correct |
6 ms |
1468 KB |
Output is correct |
5 |
Correct |
7 ms |
1348 KB |
Output is correct |
6 |
Correct |
6 ms |
1572 KB |
Output is correct |
7 |
Correct |
7 ms |
1348 KB |
Output is correct |
8 |
Incorrect |
7 ms |
1560 KB |
Wrong Answer [7] |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
4332 KB |
Output is correct |
2 |
Partially correct |
27 ms |
4776 KB |
Partially correct |
3 |
Incorrect |
40 ms |
4556 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
43 ms |
4564 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |