#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define enrraiza enraiza
#define g pqissog
#define prof pqissoprof
#define n pqisson
#define m pqissom
#define dfs pqissodfs
#define enraiza pqissoenraiza
#define x xdfs
const int MAXN=2e4+5;
vector<int> g[MAXN];
int prof[MAXN];
int n, m;
ll x;
void dfs(int cur, int p) {
prof[cur]=p;
for(auto viz : g[cur]) {
if(prof[viz]!=-1) continue;
dfs(viz, p+1);
}
}
bool enraiza(int ori) {
memset(prof, -1, sizeof(prof));
dfs(ori, 0);
for(int i=1; i<=n; i++) if(prof[i]>=59) return 1;
return 0;
}
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++) g[A[i]].push_back(B[i]), g[B[i]].push_back(A[i]);
x=X;
for(int i=0; i<n; i++) {
if(enraiza(i)) {
// printf("joi raiz = %d\n", i);
break;
}
}
for(int i=0; i<n; i++) {
int ind=prof[i]%60;
bool val=x&(1<<ind);
MessageBoard(i, val);
// printf("escreve no %d: %d >> %d %d\n", i, prof[i], ind, val);
}
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define enrraiza enraiza
const int MAXN=2e4+5;
vector<int> g[MAXN];
int prof[MAXN], pai[MAXN], prox[MAXN];
set<pair<int, bool> > resp;
int n, m;
int raiz;
bool dfs(int cur, int p, int k) {
prof[cur]=p;
bool estado=0;
for(auto viz : g[cur]) {
if(prof[viz]!=-1) continue;
bool aux=dfs(viz, p+1, k);
estado|=aux;
if(k) {
pai[viz]=cur;
if(aux) prox[cur]=viz;
}
}
return (p>=59)||(estado);
}
bool enraiza(int ori) {
memset(prof, -1, sizeof(prof));
return dfs(ori, 0, 0);
}
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++) g[A[i]].push_back(B[i]), g[B[i]].push_back(A[i]);
for(int i=0; i<n; i++) {
if(enraiza(i)) {
raiz=i;
// printf("ioi raiz = %d\n", i);
break;
}
}
memset(prof, -1, sizeof(prof));
dfs(raiz, 0, 1);
// for(int i=0; i<n; i++) printf("%d: %d %d %d\n", i, prof[i], pai[i], prox[i]);
int cur=P;
resp.insert({prof[cur]%60, V});
while(resp.size()<60&&cur!=raiz) {
cur=pai[cur];
int val=Move(cur);
// printf("Move %d %d\n", cur, val);
resp.insert({prof[cur]%60, val});
}
while(resp.size()<60) {
cur=prox[cur];
int val=Move(cur);
// printf("Move %d %d\n", cur, val);
resp.insert({prof[cur]%60, val});
}
ll respf=0;
for(auto cur : resp) if(cur.second) respf|=(1<<(cur.first));
// printf("respf %lld\n", respf);
return respf;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
2008 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
5268 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
1924 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
5172 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
5212 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |