# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1156739 | nguyn | Factories (JOI14_factories) | C++20 | 0 ms | 0 KiB |
#include "factories.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>
const int MN = 1e6 + 5;
const int inf = 1e18;
int n, q, tin[MN], tout[MN], h[MN], timedfs, f[MN][2], type[MN], s[MN], res;
pii rmq[21][MN];
vector<pii> g[MN];
vector<pii> g2[MN
void pre_dfs(int u, int p) {
tin[u] = ++timedfs;
rmq[0][timedfs] = {h[u], u};
for (auto it : g[u]) {
int v = it.F;
int w = it.S;
if (v == p) continue;
h[v] = h[u] + 1;