Submission #332879

# Submission time Handle Problem Language Result Execution time Memory
332879 2020-12-03T23:42:01 Z shrek12357 Dreaming (IOI13_dreaming) C++14
Compilation error
0 ms 0 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include <stack>
#include <bitset>
//#include "cave.h"
using namespace std;
#define ll long long
//cin.tie(0);ios_base::sync_with_stdio(0); 

const int MAXN = 1e5 + 5;

int n, m, l;
vector<pair<ll, ll>> adjList[MAXN];
bool vis[MAXN];
pair<ll, ll> best[MAXN][2];
vector<ll> nodes;
ll mx = 1e12, idx = 0;
ll ans = 0;

void dfs(int src, int p) {
	vis[src] = true;
	for (auto i : adjList[src]) {
		if (i.first == p) {
			continue;
		}
		dfs(i.first, src);
		if(best[i.first][0].first + i.second > best[src][0].first){
			best[src][1] = best[src][0];
			best[src][0] = best[i.first][0];
			best[src][0].first += i.second;
			best[src][0].second = i.first;
		}
		else if (best[i.first][0].first + i.second > best[src][1].first) {
			best[src][1] = best[i.first][0];
			best[src][1].first += i.second;
			best[src][1].second = i.first;
		}
	}
}

void cnt(int src, int p, int dist) {
	if (p != -1) {
		if (best[p][0].second != src) {
			if (best[p][0].first + dist > best[src][0].first) {
				best[src][1] = best[src][0];
				best[src][0] = best[p][0];
				best[src][0].first += dist;
				best[src][0].second = p;
			}
			else if (best[p][0].first + dist > best[src][1].first) {
				best[src][1] = best[p][0];
				best[src][1].first += dist;
				best[src][1].second = p;
			}
		}
		else {
			if (best[p][1].first + dist > best[src][0].first) {
				best[src][1] = best[src][0];
				best[src][0] = best[p][1];
				best[src][0].first += dist;
				best[src][0].second = p;
			}
			else if (best[p][1].first + dist > best[src][1].first) {
				best[src][1] = best[p][1];
				best[src][1].first += dist;
				best[src][1].second = p;
			}
		}
	}
	for (auto i : adjList[src]) {
		if (i.first == p) {
			continue;
		}
		cnt(i.first, src, i.second);
	}
}

void add(int src, int p) {
	mx = min(mx, best[src][0].first);
	ans = max(ans, best[src][0].first + best[src][1].first);
	if (mx == best[src][0].first) {
		idx = src;
	}
	for (auto i : adjList[src]) {
		if (i.first == p) {
			continue;
		}
		add(i.first, src);
	}
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	n = N; m = M; l = L;
	for (int i = 0; i < m; i++) {
		adjList[A[i]].push_back({ B[i], T[i] });
		adjList[B[i]].push_back({ A[i], T[i] });
	}
	for (int i = 0; i < n; i++) {
		if (!vis[i]) {
			mx = 1e9;
			idx = 0;
			dfs(i, -1);
			cnt(i, -1, 0);
			add(i, -1);
			nodes.push_back(mx);
		}
	}
	//for (int i = 0; i < n; i++) {
	//	cout << i << " " << best[i]->first << endl;
	//}
	//cout << ans << endl;
	sort(nodes.begin(), nodes.end());
	reverse(nodes.begin(), nodes.end());
	ans = max(ans, nodes[0] + l + nodes[1]);
	ans = max(ans, nodes[1] + l + l + nodes[2]);
	return ans;
}

Compilation message

/tmp/ccsSPbmE.o: In function `main':
grader.c:(.text.startup+0xc9): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status