Submission #831337

# Submission time Handle Problem Language Result Execution time Memory
831337 2023-08-20T06:03:20 Z OrazB Dreaming (IOI13_dreaming) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second

const int N = 1e5+5;

int dpt[N], cur[N], vis[N], mx;
pii dp[N][2];
vector<pii> E[N];

void calc(int nd, int pr, int w){
	vis[nd] = 1;
	vector<pii> vec;
	for (auto i : E[nd]){
		if (i.ff == pr) continue;
		calc(i.ff, nd, w+i.ss);
		vec.pb({dp[i.ff][0].ff+i.ss, i.ff});
	}
	sort(all(vec));
	if (!vec.size()) return;
	if (vec.size() == 1) dp[nd][0] = vec.back();
	else{
		dp[nd][0] = vec[vec.size()-1];
		dp[nd][1] = vec[vec.size()-2];
	}
}

void dfs(int nd, int pr, int t, int r){
	vis[nd] = 1;

	dpt[nd] = max(r, dp[nd][0].ff);
	
	mx = max(mx, dpt[nd]);
	
	cur[t] = min(cur[t], dpt[nd]);

	for (auto i : E[nd]){
		if (i.ff == pr) continue;
		if (dp[nd][0].ss == i.ff) dfs(i.ff, nd, t, max(r+i.ss, dp[nd][1].ff+i.ss));
		else dfs(i.ff, nd, t, max(r+i.ss, dp[nd][0].ff+i.ss));
	}
}

int travelTime(int n, int m, int L, int A[], int B[], int T[]){
	for (int i = 0; i < m; i++){
		A[i]++;
		B[i]++;
		E[A[i]].pb({B[i], T[i]});
		E[B[i]].pb({A[i], T[i]});
	}
	for (int i = 1; i <= n; i++){
		if (!vis[i]) calc(i, 0, 0);	
	} 
	for (int i = 1; i <= n; i++){
		vis[i] = 0;
		cur[i] = 2e9+7;
	}
	int t=0;
	for (int i = 1; i <= n; i++){
		if (!vis[i]){
			t++;
			dfs(i, 0, t, 0);
		} 
	}
	vector<int> vec;
	for (int i = 1; i <= t; i++) vec.pb(cur[i]);
	sort(all(vec));
	if (vec.size() == 1) return mx;
	if (vec.size() == 2) return max(mx, vec[0]+vec[1]+L);
	return max({mx, vec[vec.size()-1]+vec[vec.size()-2]+L, vec[vec.size()-2]+vec[vec.size()-3]+2*L});
}

// int main ()
// {
// 	ios::sync_with_stdio(false);
// 	cin.tie(0);
// 	int n, m, l;
// 	cin >> n >> m >> l;
// 	int A[m], B[m], T[m];
// 	for (int i = 0; i < m; i++) cin >> A[i] >> B[i] >> T[i];
// 	cout << travelTime(n, m, l, A, B, T);
// }	

Compilation message

/usr/bin/ld: /tmp/cccrDWsT.o: in function `main':
grader.c:(.text.startup+0xd1): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status