# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
97173 | maruii | Snowy Roads (JOI16_snowy) | 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 "Anyalib.h"
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
static vector<int> edge[500];
static int A[500], B[500], prt[500], dth[500], c[500], N, piv;
static void dfs(int x){
for(auto &i: edge[x]){
if(prt[x]==i) continue;
prt[i] = x;
dth[i] = dth[x]+1;
dfs(i);
}
}
static void dfs2(int x){
for(auto &i: edge[x]){
if(prt[x]==i) continue;
if(x) c[x] += c[prt[x]];
dfs2(i);
}
if(dth[x]%10 == 0) for(int i=0; i<9; ++i) Save(piv++, (c[x]>>i) & 1);
}
void InitAnya(int N_ , int AA[] , int BB[]) {
N = N_;
for(int i=0; i<N; ++i) edge[i].clear();
for(int i=0; i<N-1; ++i){
A[i] = AA[i], B[i] = BB[i];
edge[A[i]].push_back(B[i]);
edge[B[i]].push_back(A[i]);
}
for(int i=0; i<N; ++i) sort(edge[i].begin(), edge[i].end());
dfs(0);
}
void Anya(int C[]) {
for(int i=0; i<N-1; ++i) Save(prt[A[i]]==B[i]?A[i]:B[i], C[i]), c[prt[A[i]]==B[i]?A[i]:B[i]] = C[i];
piv = N;
dfs2(0);
}
#include "Anyalib.h"
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
static vector<int> edge[500];
static int A[500], B[500], prt[500], dth[500], c[500], N, piv;
static void dfs(int x){
for(auto &i: edge[x]){
if(prt[x]==i) continue;
prt[i] = x;
dth[i] = dth[x]+1;
dfs(i);
}
}
static void dfs2(int x){
for(auto &i: edge[x]){
if(prt[x]==i) continue;
if(x) c[x] += c[prt[x]];
dfs2(i);
}
if(dth[x]%10 == 0) for(int i=0; i<9; ++i) Save(piv++, (c[x]>>i) & 1);
}
void InitAnya(int N_ , int AA[] , int BB[]) {
N = N_;
for(int i=0; i<N; ++i) edge[i].clear();
for(int i=0; i<N-1; ++i){
A[i] = AA[i], B[i] = BB[i];
edge[A[i]].push_back(B[i]);
edge[B[i]].push_back(A[i]);
}
for(int i=0; i<N; ++i) sort(edge[i].begin(), edge[i].end());
dfs(0);
}
void Anya(int C[]) {
for(int i=0; i<N-1; ++i) Save(prt[A[i]]==B[i]?A[i]:B[i], C[i]), c[prt[A[i]]==B[i]?A[i]:B[i]] = C[i];
piv = N;
dfs2(0);
}