Submission #306836

# Submission time Handle Problem Language Result Execution time Memory
306836 2020-09-26T10:42:11 Z amunduzbaev Dreaming (IOI13_dreaming) C++14
Compilation error
0 ms 0 KB
#include "dreaming.h"
#include <bits/stdc++.h>
#include "grader.c"
using namespace std;
int n;
const int N = 1e5+5;
bool used[N];
vector<pair<int, int>> edges[N];
// dfs for calculating maximum depth. (a[i] - distance from the root)
int mx, mxind;
vector<int> vertex;
vector<int> a, b;
void dfs(int u, int p, int dist, bool flag){
	if(flag)a[u] = dist;
	else b[u] = dist;
	if(dist > mx){
		mx = dist;
		mxind = u;
	}
	for(auto X : edges[u]){
		int v = X.first;
		int cost = X.second;
		if(v == p)continue;
		dfs(v, u, dist + cost, flag);
	}
}
//extra dfs
void dfs2(int u, int p, int dist){
	vertex.push_back(u);
	used[u] = true;
	if(dist > mx){
		mx = dist;
		mxind = u;
	}
	for(auto X : edges[u]){
		int v = X.first;
		int cost = X.second;
		if(v == p)continue;
		dfs2(v, u, dist + cost);
	}
}

//calculate best center for the tree
int max_diameter;
int calculate_center(int u){
	vertex.clear();
	mx = -1;
	dfs2(u, u, 0);
	mx = -1;
	int ind1 = mxind;
	dfs(ind1, ind1, 0, 1);

	int ind2 = mxind;
	dfs(ind2, ind2, 0, 0);
	max_diameter = max(max_diameter, mx);
	int mn = INT_MAX;
	for(auto x : vertex){
		mn = min(mn, max(a[x], b[x]));
	}return mn;
}
int travelTime(int _N, int M, int L, int A[], int B[], int T[]) {
	n = _N;
	for(int i=0;i<M;i++){
		edges[A[i]].push_back({B[i], T[i]});
		edges[B[i]].push_back({A[i], T[i]});
	}
	vector<int> v;
	a.assign(n,0);
	b.assign(n,0);
	for(int i=0;i<n;i++){
		if(!used[i]){
			v.push_back(calculate_center(i));
		}
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	if(v.size() == 1){
		return max_diameter;
	}else {
		return max(max(max_diameter, v[0]+v[1]+L), ((v.size() > 2)? v[1]+v[2]+L*2 : 0));
	}
}

Compilation message

/tmp/ccBb6wod.o: In function `main':
dreaming.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccmFWnxh.o:grader.c:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status