#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=2e4+5;
static vector<int> g[MAXN];
static int prof[MAXN];
static int n, m;
static ll x;
void dfss(int cur, int p) {
prof[cur]=p;
for(auto viz : g[cur]) {
if(prof[viz]!=-1) continue;
dfss(viz, p+1);
}
}
bool enraizaa(int ori) {
memset(prof, -1, sizeof(prof));
dfss(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(enraizaa(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;
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];
// printf("sobe %d %d\n", cur, cur);
int val=Move(cur);
resp.insert({prof[cur]%60, val});
}
while(resp.size()<60) {
cur=prox[cur];
// printf("desce %d %d\n", cur, cur);
int val=Move(cur);
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 |
6 ms |
1972 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
4768 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
1792 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
4828 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
4812 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |