# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
17155 | murat | Dreaming (IOI13_dreaming) | C++98 | 141 ms | 42704 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>
#include "dreaming.h"
using namespace std;
#define foreach(it, x) for(type(x) it = x.begin(); it != x.end(); it++)
#define type(x) __typeof(x.begin())
#define pb push_back
#define mp make_pair
#define nd second
#define st first
const int N = 1e6 + 5;
const int inf = 1e9 + 5;
typedef pair< int , int > pii;
static int n, m, x, y, z, val[N], h[N];
static vector< pii > v[N];
pii dfs(int node, int root = 0) {
pii tt = mp(0, node);
foreach(it, v[node])
if(it->st != root) {
pii temp = dfs(it->st, node);
temp.st += it->nd;
tt = max(tt, temp);
}
return tt;
}
static void dfs2(int node, int root = 0, int dist = 0) {
val[node] = max(val[node], dist);
foreach(it, v[node])
if(it->st != root)
dfs2(it->st, node, dist + it->nd);
}
static int take(int node, int root = 0) {
int nnn = node;
h[node] = 1;
foreach(it, v[node])
if(it->st != root) {
int ttt = take(it->st, node);
if(val[ttt] < val[nnn])
nnn = ttt;
}
return nnn;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
n = N;
for(int i = 0; i < N; i++)
v[i].clear();
for(int i = 0; i < M; i++) {
int x = A[i], y = B[i], z = T[i];
v[x].pb(mp(y, z));
v[y].pb(mp(x, z));
}
vector< pii > gg;
memset(val, 0, sizeof val);
memset(h, 0, sizeof h);
for(int i = 0; i < N; i++) {
if(!h[i]) {
int x = dfs(i).nd, y = dfs(x).nd;
dfs2(x); dfs2(y);
int nnn = take(i);
gg.pb(mp(val[nnn], nnn));
}
}
sort(gg.begin(), gg.end(), greater< pii >());
for(int i = 1; i < gg.size(); i++) {
v[gg[i].nd].pb(mp(gg[0].nd, L));
v[gg[0].nd].pb(mp(gg[i].nd, L));
}
int x = dfs(0).nd, ans = dfs(x).st;
return ans;
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |