Submission #306674

# Submission time Handle Problem Language Result Execution time Memory
306674 2020-09-26T05:45:38 Z syy Dreaming (IOI13_dreaming) C++17
0 / 100
65 ms 13176 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

int n, m, l;
pi par[100005];
vpi adj[100005];
bool vis[100005];
vi v;

pi dfs(int x, int p) {
	vis[x] = 1;
	pi res = pi(0, x);
	for (auto it:adj[x]) if (it.f != p) {
		par[it.f] = pi(x, it.s);
		pi t = dfs(it.f, x);
		res = max(res, pi(t.f + it.s, t.s));
	}
	return res;
}

int travelTime(int N, int M, int L, int a[], int b[], int c[]) {
    n = N, m = M;
    FOR(i, 0, m-1) {
		adj[a[i]].pb(pi(b[i], c[i]));
		adj[b[i]].pb(pi(a[i], c[i]));
	}
	if (m == n-1) return dfs(dfs(0, -1).s, -1).f;
	FOR(i, 0, n-1) if (!vis[i]) {
		int x = dfs(i, -1).s;
		par[x] = pi(-1, -1);
		auto [dist, y] = dfs(x, -1);
		int best = dist, cur = 0;
		while (par[y].f != -1) {
			cur += par[y].s; y = par[y].f;
			best = min(best, max(cur, dist-cur));
		}
		v.pb(best);
	}
	sort(all(v), greater<int>());
	return v[0] + v[1] + L;
}
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 13176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 13176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 13176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 6196 KB Output is correct
2 Incorrect 31 ms 6280 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 13176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 13176 KB Output isn't correct
2 Halted 0 ms 0 KB -