Submission #104070

# Submission time Handle Problem Language Result Execution time Memory
104070 2019-04-03T23:04:15 Z pedro_sponchiado Dreaming (IOI13_dreaming) C++17
Compilation error
0 ms 0 KB
#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010;

vector<int> adj[maxn], peso[maxn];

int raio1, raio2;

int dist[maxn], pai[maxn];
int marc[maxn];

void dfs(int u){
	marc[u]=1;
	for(int i=0; i<adj[u].size(); i++){
		int v=adj[u][i];
		if(v!=pai[u]){
			pai[v]=u;
			dist[v]=dist[u]+peso[u][i];
			dfs(v);
		}
	}
	return;
}

pair<int, int> proximos_raios(int a){
	dist[a]=0;
	dfs(a);
	int maxi, maior1;
	for(int i=1; i<=n; i++){
		if(maxi<dist[i]){
			maior1=i;
			maxi=dist[i];
		}
	}
	
	dist[maior1]=0;
	dfs(maior1);
	maxi=0;
	for(int i=1; i<=n; i++){
		if(maxi<dist[i]){
			maior2=i;
			maxi=dist[i];
		}
	}
	
	int at=maior2;
	pair<int, int> resp;
	while(at!=maior1){
		if(max(resp.first, resp.second)> max(dist[at], dist[maior2]-dist[at]) ){
			resp=make_pair(dist[at], dist[maior2]-dist[at]);
		}	
	}
	if(resp.first>resp.second) swap(resp.first, resp.second);
	return resp;
}


int travelTime(int n, int m, int l, int A[], int B[], int T[]) {
    
    for(int i=0; i<m; i++){
    	adj[A[i]].push_back(B[i]);
		adj[B[i]].push_back(A[i]);
		peso[A[i]].push_back(T[i]);
		peso[B[i]].push_back(T[i]);
	}
	
	raio1=-1;
	for(int i=0; i<n; i++){
		if(marc[i]==0){
		
			pair<int, int> p=proximos_raios(i);
			if(raio1==-1){
				raio1=p.first;
				raio2=p.second;
				continue;
			}
		
			if(raio2>p.second){
				raio1=raio2;
				raio2=max(p.second+l, raio1);
			}
			
			else{
				raio1=p.second;
				raio2=max(raio2+l, p.first);
			}
			
			if(raio1>raio2) swap(raio1, raio2);
		}
	}
	
	return raio1+raio2;
}

Compilation message

dreaming.cpp: In function 'void dfs(int)':
dreaming.cpp:15:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<adj[u].size(); i++){
               ~^~~~~~~~~~~~~~
dreaming.cpp: In function 'std::pair<int, int> proximos_raios(int)':
dreaming.cpp:30:18: error: 'n' was not declared in this scope
  for(int i=1; i<=n; i++){
                  ^
dreaming.cpp:40:18: error: 'n' was not declared in this scope
  for(int i=1; i<=n; i++){
                  ^
dreaming.cpp:42:4: error: 'maior2' was not declared in this scope
    maior2=i;
    ^~~~~~
dreaming.cpp:42:4: note: suggested alternative: 'maior1'
    maior2=i;
    ^~~~~~
    maior1
dreaming.cpp:47:9: error: 'maior2' was not declared in this scope
  int at=maior2;
         ^~~~~~
dreaming.cpp:47:9: note: suggested alternative: 'maior1'
  int at=maior2;
         ^~~~~~
         maior1