# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
922938 | vjudge1 | Digital Circuit (IOI22_circuit) | C++17 | 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>
#define pb push_back
using namespace std;
const int N = 2e5 + 5;
const int mod = 1000002022;
void add(int &a, int b){
a += b;
if (a >= mod) a -= mod;
if (a < 0) a += mod;
}
vector <int> adj[N], pre[N], suf[N];
int sz[N], val[N];
void dfs(int u){
sz[u] = 1;
for (int i = 0; i < adj[u].size(); ++ i){
int v = adj[u][i];
dfs(v);
if (!i) pre[u].pb(sz[v]);
else pre[u].pb(1ll * pre[u].back() * sz[v] % mod);
suf[u].pb(0);
sz[u] += sz[v];
}
for (int i = adj[u].size() - 1; i >= 0; -- i){
int v = adj[u][i];
if (i == int(adj[u].size() - 1)) suf[u][i] = sz[v];