#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&(1LL<<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|=(1LL <<(cur.first));
// printf("respf %lld\n", respf);
return respf;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1928 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
5268 KB |
Output is correct |
2 |
Correct |
28 ms |
5268 KB |
Output is correct |
3 |
Correct |
27 ms |
5140 KB |
Output is correct |
4 |
Execution timed out |
3033 ms |
1536 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1920 KB |
Output is correct |
2 |
Correct |
5 ms |
1924 KB |
Output is correct |
3 |
Correct |
4 ms |
1924 KB |
Output is correct |
4 |
Correct |
6 ms |
2364 KB |
Output is correct |
5 |
Correct |
7 ms |
2236 KB |
Output is correct |
6 |
Correct |
8 ms |
2500 KB |
Output is correct |
7 |
Correct |
7 ms |
2372 KB |
Output is correct |
8 |
Correct |
7 ms |
2364 KB |
Output is correct |
9 |
Correct |
16 ms |
4760 KB |
Output is correct |
10 |
Correct |
16 ms |
4528 KB |
Output is correct |
11 |
Correct |
15 ms |
4664 KB |
Output is correct |
12 |
Correct |
4 ms |
2004 KB |
Output is correct |
13 |
Correct |
4 ms |
1924 KB |
Output is correct |
14 |
Correct |
4 ms |
1932 KB |
Output is correct |
15 |
Correct |
4 ms |
1932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
5124 KB |
Output is correct |
2 |
Correct |
28 ms |
5132 KB |
Output is correct |
3 |
Correct |
28 ms |
5140 KB |
Output is correct |
4 |
Execution timed out |
3028 ms |
1508 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
5088 KB |
Output is correct |
2 |
Correct |
27 ms |
5276 KB |
Output is correct |
3 |
Correct |
28 ms |
5116 KB |
Output is correct |
4 |
Execution timed out |
3012 ms |
1536 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |