# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
476974 | nicolaalexandra | Amusement Park (JOI17_amusement_park) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "joi.h"
#define DIM 1010
using namespace std;
static vector <int> L[DIM];
static int viz[DIM],val[DIM],idx,n;
/*void MessageBoard (int x, int y){
return;
}
*/
void dfs (int nod){
viz[nod] = 1;
val[nod] = (++idx) % 60; /// ce bit ii atribui
for (auto vecin : L[nod])
if (!viz[vecin])
dfs (vecin);
}
void Joi (int _n, int m, int a[], int b[], long long x, int useless){
n = _n;
for (int i=0;i<m;i++){
a[i]++, b[i]++;
L[a[i]].push_back(b[i]);
L[b[i]].push_back(a[i]);
}
memset (viz,0,sizeof viz);
memset (val,0,sizeof val);
idx = -1;
dfs (1);
for (int i=1;i<=n;i++){
int bit = val[i];
if (x & (1LL<<bit))
MessageBoard(i-1,1);
else MessageBoard(i-1,0);
}
}
/*
int main (){
ifstream cin ("date.in");
ofstream cout ("date.out");
int n,m,x,i,a[100],b[100];
cin>>n>>m>>x;
for (i=0;i<m;i++)
cin>>a[i]>>b[i];
Joi(n,m,a,b,x,1);
for (i=1;i<=n;i++)
cout<<val[i];
return 0;
}*/
#include <bits/stdc++.h>
#include "ioi.h"
#define DIM 1010
using namespace std;
static vector <int> L[DIM],edg[DIM];
static int viz[DIM],val[DIM],fth[DIM],s[DIM],f[70],idx,n,cnt;
/*int Move (int dest){
//return value[dest+1];
}
*/
void add_edge (int x, int y){
edg[x].push_back(y);
edg[y].push_back(x);
}
void dfs (int nod){
viz[nod] = s[nod] = 1;
val[nod] = (++idx) % 60; /// ce bit ii atribui
for (auto vecin : L[nod])
if (!viz[vecin]){
fth[vecin] = nod;
add_edge (nod,vecin);
dfs (vecin);
s[nod] += s[vecin];
}
}
void dfs2 (int nod, int tata){
if (cnt == 60)
return;
for (auto vecin : edg[nod])
if (vecin != tata){
int ans = Move(vecin);
if (f[val[vecin]] == -1)
cnt++;
f[val[vecin]] = ans;
if (cnt == 60)
return;
dfs2 (vecin,nod);
Move(nod); /// trb sa ma intorc inapoi
}
}
long long Ioi (int _n, int m, int a[], int b[], int start, int val_start, int useless){
n = _n;
for (int i=0;i<m;i++){
a[i]++, b[i]++;
L[a[i]].push_back(b[i]);
L[b[i]].push_back(a[i]);
}
memset (viz,0,sizeof viz);
memset (val,0,sizeof val);
idx = -1;
dfs (1);
memset (f,-1,sizeof f);
start++;
cnt = 0;
if (f[val[start]] == -1){
f[val[start]] = val_start;
cnt = 1;
}
while (s[start] < 60){
start = fth[start];
Move(start);
}
dfs2 (start,0);
long long sol = 0;
for (int i=0;i<60;i++)
if (f[i])
sol += (1LL<<i);
return sol;
}
/*int main (){
ifstream cin ("date.in");
ofstream cout ("date.out");
return 0;
}*/