#include "Joi.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
namespace{
int n, m;
vector<int> link[10002];
int depth[10002], par[10002], maxDepth[10002];
bool visited[10002];
bool existPath;
int in[10002], inCnt;
void dfs(int x, int dp=0){
visited[x] = 1;
depth[x] = dp;
vector<int> newLink;
for(auto y: link[x]){
if(visited[y]) continue;
newLink.push_back(y);
par[y] = x;
dfs(y, dp+1);
maxDepth[x] = max(maxDepth[x], maxDepth[y]+1);
}
link[x].swap(newLink);
}
void dfs2(int x){
visited[x] = 1;
in[x] = inCnt++;
for(auto y: link[x]){
if(visited[y]) continue;
dfs2(y);
}
}
}
void Joi(int N, int M, int A[], int B[], ll X, int T) {
n = N, m = M;
for(int i=0; i<m; i++){
link[A[i]].push_back(B[i]);
link[B[i]].push_back(A[i]);
}
dfs(0);
existPath = (maxDepth[0] >= 59);
if(existPath){
for(int i=0; i<n; i++){
MessageBoard(i, (X>>(depth[i]%60))&1);
}
}
else{
memset(visited, 0, sizeof(visited));
dfs2(0);
for(int i=0; i<n; i++){
MessageBoard(i, (X>>(in[i])%60)&1);
}
}
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
namespace{
const ll INF = (1LL<<60)-1;
int n, m;
vector<int> link[10002];
int depth[10002], par[10002], maxDepth[10002];
int LCADB[10002][16];
bool visited[10002];
bool existPath;
int in[10002], inCnt, idx[10002];
int minDist = 10000;
vector<int> runway;
int DP[10002];
int L, R;
void dfs(int x, int dp=0){
visited[x] = 1;
depth[x] = dp;
vector<int> newLink;
for(auto y: link[x]){
if(visited[y]) continue;
newLink.push_back(y);
par[y] = x;
dfs(y, dp+1);
maxDepth[x] = max(maxDepth[x], maxDepth[y]+1);
}
link[x].swap(newLink);
}
void dfs2(int x){
visited[x] = 1;
idx[inCnt] = x;
in[x] = inCnt++;
for(auto y: link[x]){
if(visited[y]) continue;
dfs2(y);
}
}
int getLCA(int x, int y){
if(depth[x] > depth[y]) swap(x, y);
for(int d=0; d<16; d++) if((depth[y]-depth[x]) & (1<<d)) y = LCADB[y][d];
if(x==y) return x;
for(int d=15; d>=0; d--) if(LCADB[x][d] != LCADB[y][d]) x = LCADB[x][d], y = LCADB[y][d];
return par[x];
}
int dist(int x, int y){
return depth[x] + depth[y] - 2*depth[getLCA(x, y)];
}
void dfs3(int x){
DP[x] = (L <= x && x <= R) ? 1 : 0;
for(auto y: link[x]){
dfs3(y);
DP[x] += DP[y];
}
}
bool dfs4(int x, int avoid, int p=-1){ /// üũ�� ������ ��� �湮�ϵ�, avoid�� ���� �������� �湮�Ѵ�.
runway.push_back(x);
if(x == avoid) return true;
vector<int> linked;
int dir = -1;
for(auto y: link[x]) if(y!=p && DP[y]){
if(dist(x, avoid) == dist(y, avoid)+1) dir = y;
else linked.push_back(y);
}
if(x && par[x]!=p && DP[x]!=60){
if(dist(x, avoid) == dist(par[x], avoid)+1) dir = par[x];
else linked.push_back(par[x]);
}
if(dir!=-1) linked.push_back(dir);
bool ret = 0;
for(auto y: linked){
if(dfs4(y, avoid, x)) ret = true;
else runway.push_back(x);
}
return ret;
}
void trySolution(int l, int r, int x){ /// ���� in, �� in, ������ ��ȣ
L = l, R = r;
dfs3(0);
int validPoints = 1;
for(int i=0; i<n; i++) if(DP[i] && DP[i] < 60) validPoints++;
int Farthest = 0, FarDist = -1;
for(int i=l; i<=r; i++){
int y = idx[i];
if(dist(x, y) > FarDist) Farthest = y, FarDist = dist(x, y);
}
int len = 2*(validPoints-1) - FarDist;
if(minDist <= len) return;
minDist = len;
runway.clear();
assert(dfs4(x, Farthest));
}
}
ll Ioi(int N, int M, int A[], int B[], int P, int V, int T){
n = N, m = M;
for(int i=0; i<m; i++){
link[A[i]].push_back(B[i]);
link[B[i]].push_back(A[i]);
}
dfs(0);
existPath = (maxDepth[0] >= 59);
if(existPath){ /// �ö� �������� ��
int x = P;
ll ans = 0;
if(depth[x] >= 59){ /// �ö� ��
for(int cnt=0; cnt<59; cnt++){
if(V) ans += (1LL << (depth[x] % 60));
V = Move(x = par[x]);
}
if(V) ans += (1LL << (depth[x] % 60));
return ans;
}
while(x){
V = Move(x = par[x]);
}
for(int cnt=0; cnt<59; cnt++){
if(V) ans += (1LL << cnt);
int nxt = -1;
for(auto y: link[x]){
if(cnt + maxDepth[y] >= 58){
nxt = y;
break;
}
}
assert(nxt != -1);
V = Move(x = nxt);
}
if(V) ans += (1LL << 59);
return ans;
}
int x = P;
memset(visited, 0, sizeof(visited));
dfs2(0);
for(int i=0; i<n; i++) LCADB[i][0] = par[i];
for(int d=1; d<16; d++) for(int i=0; i<n; i++) LCADB[i][d] = LCADB[LCADB[i][d-1]][d-1];
for(int a=max(0, in[x]-59); a<=in[x] && a+59<n; a++){
int b = a+59;
trySolution(a, b, x);
}
ll ans = 0;
for(auto nxt: runway){
if(x==nxt) continue;
if(V) ans |= (1LL << (in[x]%60));
V = Move(x = nxt);
}
if(V) ans |= (1LL << in[x]%60);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1152 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
5132 KB |
Output is correct |
2 |
Correct |
23 ms |
5176 KB |
Output is correct |
3 |
Correct |
23 ms |
5252 KB |
Output is correct |
4 |
Runtime error |
15 ms |
5400 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1024 KB |
Output is correct |
2 |
Correct |
1 ms |
1148 KB |
Output is correct |
3 |
Correct |
2 ms |
1160 KB |
Output is correct |
4 |
Correct |
2 ms |
1820 KB |
Output is correct |
5 |
Correct |
2 ms |
1820 KB |
Output is correct |
6 |
Correct |
2 ms |
1820 KB |
Output is correct |
7 |
Correct |
3 ms |
1816 KB |
Output is correct |
8 |
Correct |
2 ms |
1820 KB |
Output is correct |
9 |
Correct |
12 ms |
5712 KB |
Output is correct |
10 |
Correct |
11 ms |
5792 KB |
Output is correct |
11 |
Correct |
12 ms |
5708 KB |
Output is correct |
12 |
Correct |
0 ms |
1156 KB |
Output is correct |
13 |
Correct |
1 ms |
1152 KB |
Output is correct |
14 |
Correct |
1 ms |
1024 KB |
Output is correct |
15 |
Correct |
0 ms |
1032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
5192 KB |
Output is correct |
2 |
Correct |
24 ms |
5212 KB |
Output is correct |
3 |
Correct |
27 ms |
5208 KB |
Output is correct |
4 |
Runtime error |
15 ms |
5444 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
5216 KB |
Output is correct |
2 |
Correct |
25 ms |
5240 KB |
Output is correct |
3 |
Correct |
20 ms |
5544 KB |
Output is correct |
4 |
Runtime error |
15 ms |
5500 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |