답안 #334231

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334231 2020-12-08T17:29:48 Z LucaDantas 꿈 (IOI13_dreaming) C++17
0 / 100
58 ms 12908 KB
#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;

using pii = pair<int,int>;

#define ff first
#define ss second
#define pb push_back

constexpr int maxn = 1e5+10, inf = 0x3f3f3f3f;

vector<pii> g[maxn];
pair<pii,pii> top[maxn];
bool mark[maxn];
int ans, diam;

int dfs(int u, int p) {
	mark[u] = 1;
	for(pii pp : g[u]) {
		int v = pp.ff, w = pp.ss;
		if(v != p) {
			int val = dfs(v, u) + w;
			if(val > top[u].ff.ff) top[u].ss = top[u].ff, top[u].ff = {val, v};
			else if(val > top[u].ss.ff) top[u].ss = {val, v};
		}
	}
	diam = max(diam, top[u].ff.ff + top[u].ss.ff);
	return top[u].ff.ff;
}

void dfs2(int u, int p, int up) {
	ans = min(ans, max(top[u].ff.ff, up));
	// printf("%d %d\n", u, max(top[u].ff.ff, up));
	for(pii pp : g[u]) {
		int v = pp.ff, w = pp.ss;
		if(v != p)
			dfs2(v, u,w + max(up,
				(v != top[u].ff.ss?top[u].ff.ff:top[u].ss.ff)));
	}
}

struct ANS
{
	int a, b, c;
	void upd(int x) {
		if(x >= a) c = b, b = a, a = x;
		else if(x >= b) c = b, b = x;
		else if(x >= c) c = x;
	}
	// void db() { printf("ans %d %d %d\n", a, b, c); }
	inline int get(int x) { return max(a+b+x, b+c+2*x); }
} opa;

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	for(int i = 0; i < M; i++)
		g[A[i]].pb({B[i], T[i]}), g[B[i]].pb({A[i], T[i]});
	for(int i = 0; i < N; i++)
		if(!mark[i])
			ans = inf, dfs(i, -1), dfs2(i, -1, 0), assert(ans<inf), opa.upd(ans);
	return max(opa.get(L), diam);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 12908 KB Output is correct
2 Correct 58 ms 12908 KB Output is correct
3 Correct 39 ms 11500 KB Output is correct
4 Correct 9 ms 4352 KB Output is correct
5 Correct 7 ms 3712 KB Output is correct
6 Correct 14 ms 5228 KB Output is correct
7 Incorrect 2 ms 2668 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 12908 KB Output is correct
2 Correct 58 ms 12908 KB Output is correct
3 Correct 39 ms 11500 KB Output is correct
4 Correct 9 ms 4352 KB Output is correct
5 Correct 7 ms 3712 KB Output is correct
6 Correct 14 ms 5228 KB Output is correct
7 Incorrect 2 ms 2668 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 12908 KB Output is correct
2 Correct 58 ms 12908 KB Output is correct
3 Correct 39 ms 11500 KB Output is correct
4 Correct 9 ms 4352 KB Output is correct
5 Correct 7 ms 3712 KB Output is correct
6 Correct 14 ms 5228 KB Output is correct
7 Incorrect 2 ms 2668 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 6508 KB Output is correct
2 Correct 24 ms 6636 KB Output is correct
3 Correct 26 ms 6508 KB Output is correct
4 Correct 24 ms 6508 KB Output is correct
5 Correct 24 ms 6508 KB Output is correct
6 Correct 25 ms 6764 KB Output is correct
7 Correct 27 ms 6764 KB Output is correct
8 Correct 23 ms 6508 KB Output is correct
9 Correct 23 ms 6508 KB Output is correct
10 Correct 26 ms 6688 KB Output is correct
11 Correct 2 ms 2668 KB Output is correct
12 Correct 4 ms 3564 KB Output is correct
13 Correct 4 ms 3820 KB Output is correct
14 Correct 4 ms 3564 KB Output is correct
15 Correct 4 ms 3564 KB Output is correct
16 Correct 4 ms 3436 KB Output is correct
17 Correct 4 ms 2924 KB Output is correct
18 Correct 5 ms 3948 KB Output is correct
19 Correct 4 ms 3436 KB Output is correct
20 Incorrect 2 ms 2668 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 12908 KB Output is correct
2 Correct 58 ms 12908 KB Output is correct
3 Correct 39 ms 11500 KB Output is correct
4 Correct 9 ms 4352 KB Output is correct
5 Correct 7 ms 3712 KB Output is correct
6 Correct 14 ms 5228 KB Output is correct
7 Incorrect 2 ms 2668 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 12908 KB Output is correct
2 Correct 58 ms 12908 KB Output is correct
3 Correct 39 ms 11500 KB Output is correct
4 Correct 9 ms 4352 KB Output is correct
5 Correct 7 ms 3712 KB Output is correct
6 Correct 14 ms 5228 KB Output is correct
7 Incorrect 2 ms 2668 KB Output isn't correct
8 Halted 0 ms 0 KB -