Submission #39503

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
395032018-01-16 03:48:4814kgFactories (JOI14_factories)C++11
100 / 100
4099 ms144720 KiB
#include "factories.h"
#include <algorithm>
#include <vector>
#define N 500001
#define LL long long
#define INF 999999999999999999
#define min2(x,y) (x<y?x:y)
using namespace std;
int n, t[N], tree_up[N][20], p[20];
int tree_lev[N], tree_e[N];
LL deep[N];
vector<pair<int, int> > r[N];
int dfs_lev, q_len, dfs_num;
LL out;
pair<int, int> q[N * 3];
void dfs(int x, int up, LL _deep, int _t) {
tree_lev[x] = ++dfs_lev;
deep[dfs_lev] = _deep, t[dfs_lev] = _t;
tree_up[dfs_lev][0] = tree_lev[up];
for (int i = 1; i < 20; i++)
tree_up[dfs_lev][i] = tree_up[tree_up[dfs_lev][i - 1]][i - 1];
for (auto i : r[x])
if (i.first != up) dfs(i.first, x, _deep + (LL)i.second, _t + 1);
tree_e[tree_lev[x]] = dfs_lev;
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...