답안 #304097

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
304097 2020-09-21T02:53:53 Z Fischer 꿈 (IOI13_dreaming) C++14
0 / 100
187 ms 65540 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
 
const int maxn = 1e5 + 10;
vector<pair<int, int>> g[maxn];
pair<int, int> len[maxn];
vector<int> arr;
bool vis[maxn];
 
void add(int x, int t) {
	if (t >= len[x].first) {
		len[x].second = len[x].first;
		len[x].first = t;
	} else {
		len[x].second = max(len[x].second, t);
	}
}
 
int dfs(int x, int p) {
	vis[x] = 1;
	len[x] = {0, 0};
	for (auto e : g[x]) {
		if (e.first == p) continue;
		dfs(e.first, x);
		add(x, len[e.first].first+e.second);
	}
}
 
int dfs_reroot(int x, int p, int r) {
	if (~p) {
		if (len[p].first == len[x].first+r) {
			add(x, len[p].second+r);
		} else {
			add(x, len[p].first+r);
		}
	}
	int ans = len[x].first;
	for (auto e : g[x]) {
		if (e.first == p) continue;
		ans = max(ans, dfs_reroot(e.first, x, e.second));
	}
	return ans;
}
 
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	for (int i=0; i<N; ++i) g[i].clear(), vis[i] = 0;
	for (int i=0; i<M; ++i) {
		g[A[i]].emplace_back(B[i], T[i]);
		g[B[i]].emplace_back(A[i], T[i]);
	}
	for (int i=0; i<N; ++i) {
		if (vis[i]) continue;
		dfs(i, -1);
		arr.emplace_back(dfs_reroot(i, -1, 0));
	}
	int ans = 0;
	for (int i = 0; i < N; ++i) ans = max(ans, len[i].first + len[i].second);
	sort(arr.rbegin(), arr.rend());
	if (arr.size() >= 2) ans = max(ans, arr[0] + arr[1] + L);
	if (arr.size() >= 3) ans = max(ans, arr[1] + arr[2] + 2 * L);
	return ans;
}

Compilation message

dreaming.cpp: In function 'int dfs(int, int)':
dreaming.cpp:28:1: warning: no return statement in function returning non-void [-Wreturn-type]
   28 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 187 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 187 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 187 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 23 ms 10112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 187 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 187 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -