# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
959512 | dong_gas | Factories (JOI14_factories) | C++17 | 8103 ms | 146016 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/extc++.h>
#include "factories.h"
#define all(v) v.begin(), v.end()
#define zip(v) sort(all(v)), v.erase(unique(all(v)), v.end())
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int n, q;
int sz[500050], use[500050], cent_papa[500050], papa[500050][23], dep[500050];
ll dp[500050];
vector<pint> adj[500050];
ll m[500050];
void dfs(int u, int p=0) {
papa[u][0]=p;
dep[u]=dep[p]+1;
for(auto& [v, w]: adj[u]) {
if(v==p) continue;
dp[v]=dp[u]+w;
dfs(v,u);
}
}
int lca(int u, int v) {
if(dep[u]<dep[v]) swap(u,v);
for(int i=22;i>=0;i--) if(dep[u]-dep[v]>=(1<<i)) u=papa[u][i];
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |