Submission #107823

# Submission time Handle Problem Language Result Execution time Memory
107823 2019-04-26T00:23:03 Z degelo Dreaming (IOI13_dreaming) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include"dreaming.h"
#define maxn 100005
using namespace std;
int dist[maxn][3],marc[maxn][3];
vector<int> grafo[maxn],peso[maxn],cc[maxn],raios;
void dfs(int v,int k,int id){
	marc[v][id]=k;
	for(int i=0;i<grafo[v].size();i++){
		int viz=grafo[v][i];
		int p=peso[v][i];
		if(marc[viz][id]==0){
			dist[viz][id]=dist[v][id]+p;
			dfs(viz,k,id);
		}
	}
}
int travelTime(int N,int M,int L,int A[],int B[],int T[]){
	int k=1;
	for(int i=0;i<M;i++){
		grafo[A[i]].push_back(B[i]);
		peso[A[i]].push_back(T[i]);
		grafo[B[i]].push_back(A[i]);
		peso[B[i]].push_back(T[i]);
	}
	for(int i=0;i<N;i++){
		if(marc[i][0]==0){
			dist[i][0]=0;
			dfs(i,k,0);
			k++;
		}
		cc[marc[i][0]].push_back(i);
	}
	for(int i=1;i<k;i++){
		//////////////////////////////////ACHAR a
		int a=cc[i][0];
		for(int j=0;j<cc[i].size();j++){
			int prox=cc[i][j];
			if(dist[prox][0]>dist[a][0]) a=prox;
		}
		dist[a][1]=0;
		dfs(a,i,1);
		/////////////////////////////////ACHAR b
		int b=a;
		for(int j=0;j<cc[i].size();j++){
			int prox=cc[i][j];
			if(dist[prox][1]>dist[b][1]) b=prox;
		}
		dist[b][2]=0;
		dfs(b,i,2);
		////////////////////////////////ACHAR O MAIOR RAIO
		int d=dist[b][1],r=d;
		for(int j=0;j<cc[i].size();j++){
			int cur=cc[i][j];
			int r1=dist[cur][1],r2=dist[cur][2];
			if(r1+r2==d)	r=min(r,max(r1,r2));
		}
		///////////////////////////////ACHAMOS
		raios.push_back(r);		
	}
	sort(raios.begin(),raios.end());
	int tam=raios.size();
	int m1=raios[tam-1],m2=raios[tam-2],m3;
	if(n-m>=3){
		m3=raios[tam-3];
	}
	else m3=-1000000000;
	int resp=max(m1+m2+L,m2+m3+2*L);
	for(int i=0;i<N;i++){
		grafo[i].clear();
		peso[i].clear();
		cc[i].clear();
		dist[i][0]=0;dist[i][1]=0;dist[i][2]=0;
		marc[i][0]=0;marc[i][1]=0;marc[i][2]=0;
	}
	raios.clear();
	return resp;
}
/*int main(){
	int n,m,l;
	scanf("%d %d %d",&n,&m,&l);
	int A[maxn],B[maxn],P[maxn];
	for(int i=0;i<m;i++){
		int a,b,p;
		scanf("%d %d %d",&a,&b,&p);
		A[i]=a;
		B[i]=b;
		P[i]=p;
	}
	cout<<travelTime(n,m,l,A,B,P);
}*/

Compilation message

dreaming.cpp: In function 'void dfs(int, int, int)':
dreaming.cpp:9:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<grafo[v].size();i++){
              ~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:37:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<cc[i].size();j++){
               ~^~~~~~~~~~~~~
dreaming.cpp:45:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<cc[i].size();j++){
               ~^~~~~~~~~~~~~
dreaming.cpp:53:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<cc[i].size();j++){
               ~^~~~~~~~~~~~~
dreaming.cpp:64:5: error: 'n' was not declared in this scope
  if(n-m>=3){
     ^
dreaming.cpp:64:7: error: 'm' was not declared in this scope
  if(n-m>=3){
       ^
dreaming.cpp:64:7: note: suggested alternative: 'm3'
  if(n-m>=3){
       ^
       m3