#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
const int Mxn = 10007;
bool used[Mxn];
bool f[Mxn];
vector<int> g[Mxn];
bool og[Mxn];
bool gt(long long x){
return x==0ll ? 0:1;
}
void bfs(int x,long long Val){
memset(f,0,sizeof(f));
queue<pair<int,int> > q;
q.push({x,1});
MessageBoard(x,Val&(1ll));
f[x]=true;
used[x]=true;
og[x]=true;
while(!q.empty()){
int v = q.front().first;
int step = q.front().second;
q.pop();
if(step==120)break;
for(int to:g[v]){
if(f[to])continue;
if(step>59&&used[to])continue;
if(step<=59){
MessageBoard(to,gt(Val&(1ll<<step)));
og[to]=true;
}
if(step<120){
q.push({to,step+1});
}
used[to]=f[to]=true;
}
}
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
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(used[i]==false)bfs(i,X);
}
for(int i=0;i<N;++i){
if(og[i]==false){
MessageBoard(i,0);
}
}
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
const int Mxn = 10007;
bool ussd[Mxn];
bool ff[Mxn];
vector<int> gg[Mxn];
bool is_good[Mxn];
int par[Mxn];
void bfs(int x){
memset(ff,0,sizeof(ff));
queue<pair<int,int> > q;
q.push({x,1});
ff[x]=true;
ussd[x]=true;
while(!q.empty()){
int v = q.front().first;
int step = q.front().second;
q.pop();
if(step==120)break;
for(int to:gg[v]){
if(ff[to])continue;
if(step>59&&ussd[to])continue;
if(step<120){
q.push({to,step+1});
}
ussd[to]=ff[to]=true;
}
}
}
int bfs_else(int x){
memset(ff,0,sizeof(ff));
queue<pair<int,int> > q;
q.push({x,1});
ff[x]=true;
par[x]=x;
if(is_good[x])return x;
while(!q.empty()){
int v = q.front().first;
int step = q.front().second;
q.pop();
if(step==120)break;
for(int to:gg[v]){
if(ff[to])continue;
par[to]=v;
ff[to]=true;
if(is_good[to])return to;
q.push({to,step+1});
}
}
}
int bfs_fnd(int x){
memset(ff,0,sizeof(ff));
queue<pair<int,int> > q;
q.push({x,1});
ff[x]=true;
par[x]=x;
int ls=x;
while(!q.empty()){
int v = q.front().first;
int step = q.front().second;
q.pop();
for(int to:gg[v]){
if(ff[to])continue;
par[to]=v;
ls=to;
ff[to]=true;
if(step==60)return to;
q.push({to,step+1});
}
}
return ls;
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
for(int i=0;i<M;++i){
gg[A[i]].push_back(B[i]);
gg[B[i]].push_back(A[i]);
}
vector<int> v;
for(int i = 0; i < N; i++){
if(ussd[i]==false){
bfs(i);
v.push_back(i);
is_good[i]=true;
}
}
int x=bfs_else(P);
vector<int> all;
int lst=V;
vector<int> nf;
vector<int> nf_ans;
all.push_back(V);
int o=x;
while(o!=par[o]){
nf.push_back(o);
o=par[o];
}
for(int i=nf.size()-1;i>=0;i--){
nf_ans.push_back(Move(nf[i]));
lst=nf_ans.back();
all.push_back(lst);
}
if(all.size()>=60){
long long ans=0;
for(int ast=0;ast<60;++ast){
if(all[all.size()-1-ast])
ans+=(1ll<<ast);
}
return ans;
}
int oth=bfs_fnd(x);
vector<int> nw;
nw.push_back(lst);
long long ans=lst;
int ast=0;
vector<int> perm;
while(x!=oth){
perm.push_back(oth);
oth=par[oth];
}
for(int i=perm.size()-1;i>=0;i--){
lst=Move(perm[i]);
ast++;
if(lst)
ans+=(1ll<<ast);
}
return ans;
}
Compilation message
Ioi.cpp: In function 'int bfs_else(int)':
Ioi.cpp:51:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
1356 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
45 ms |
4084 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4128 KB |
Output is correct |
2 |
Correct |
7 ms |
4128 KB |
Output is correct |
3 |
Correct |
6 ms |
4128 KB |
Output is correct |
4 |
Correct |
9 ms |
4128 KB |
Output is correct |
5 |
Correct |
8 ms |
4128 KB |
Output is correct |
6 |
Correct |
9 ms |
4128 KB |
Output is correct |
7 |
Correct |
7 ms |
4128 KB |
Output is correct |
8 |
Correct |
8 ms |
4128 KB |
Output is correct |
9 |
Correct |
24 ms |
4128 KB |
Output is correct |
10 |
Correct |
23 ms |
4340 KB |
Output is correct |
11 |
Correct |
19 ms |
4528 KB |
Output is correct |
12 |
Correct |
7 ms |
4560 KB |
Output is correct |
13 |
Correct |
7 ms |
4560 KB |
Output is correct |
14 |
Correct |
5 ms |
4560 KB |
Output is correct |
15 |
Correct |
6 ms |
4560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
37 ms |
5732 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
45 ms |
6128 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |