답안 #334232

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334232 2020-12-08T17:39:50 Z LucaDantas 꿈 (IOI13_dreaming) C++17
0 / 100
60 ms 13036 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, int comp) { return !c?0:(c==1?(a+b+x):(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]});
	int c = -1;
	for(int i = 0; i < N; i++)
		if(!mark[i])
			++c, ans = inf, dfs(i, -1), dfs2(i, -1, 0), assert(ans<inf), opa.upd(ans);
	return max(opa.get(L, c), diam);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 13036 KB Output is correct
2 Correct 59 ms 12524 KB Output is correct
3 Correct 37 ms 11136 KB Output is correct
4 Correct 8 ms 4204 KB Output is correct
5 Correct 7 ms 3564 KB Output is correct
6 Correct 14 ms 4844 KB Output is correct
7 Incorrect 2 ms 2668 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 13036 KB Output is correct
2 Correct 59 ms 12524 KB Output is correct
3 Correct 37 ms 11136 KB Output is correct
4 Correct 8 ms 4204 KB Output is correct
5 Correct 7 ms 3564 KB Output is correct
6 Correct 14 ms 4844 KB Output is correct
7 Incorrect 2 ms 2668 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 13036 KB Output is correct
2 Correct 59 ms 12524 KB Output is correct
3 Correct 37 ms 11136 KB Output is correct
4 Correct 8 ms 4204 KB Output is correct
5 Correct 7 ms 3564 KB Output is correct
6 Correct 14 ms 4844 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 23 ms 6656 KB Output is correct
3 Correct 24 ms 6508 KB Output is correct
4 Correct 27 ms 6508 KB Output is correct
5 Correct 23 ms 6508 KB Output is correct
6 Correct 27 ms 6764 KB Output is correct
7 Correct 25 ms 6764 KB Output is correct
8 Correct 24 ms 6508 KB Output is correct
9 Correct 23 ms 6508 KB Output is correct
10 Correct 25 ms 6636 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 5 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 Correct 2 ms 2668 KB Output is correct
21 Incorrect 3 ms 2668 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 13036 KB Output is correct
2 Correct 59 ms 12524 KB Output is correct
3 Correct 37 ms 11136 KB Output is correct
4 Correct 8 ms 4204 KB Output is correct
5 Correct 7 ms 3564 KB Output is correct
6 Correct 14 ms 4844 KB Output is correct
7 Incorrect 2 ms 2668 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 13036 KB Output is correct
2 Correct 59 ms 12524 KB Output is correct
3 Correct 37 ms 11136 KB Output is correct
4 Correct 8 ms 4204 KB Output is correct
5 Correct 7 ms 3564 KB Output is correct
6 Correct 14 ms 4844 KB Output is correct
7 Incorrect 2 ms 2668 KB Output isn't correct
8 Halted 0 ms 0 KB -