Submission #107825

# Submission time Handle Problem Language Result Execution time Memory
107825 2019-04-26T00:54:20 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 resp=0;
	if(tam>=3){
		int m1=raios[tam-1],m2=raios[tam-2],m3=raios[tam-3];
		int resp=max(m1+m2+L,m2+m3+2*L);
	}
	else if(tam>=2){
		int m1=raios[tam-1],m2=raios[tam-2];
		int resp=m1+m2+L;
	}
	else if(tam==1){
		int m1=raios[tam-1];
		resp=m1;
	}
	/*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:66:7: warning: unused variable 'resp' [-Wunused-variable]
   int resp=max(m1+m2+L,m2+m3+2*L);
       ^~~~
dreaming.cpp:70:7: warning: unused variable 'resp' [-Wunused-variable]
   int resp=m1+m2+L;
       ^~~~
dreaming.cpp: In function 'int main()':
dreaming.cpp:88:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n,&m,&l);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
dreaming.cpp:92:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&a,&b,&p);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
/tmp/cclNc3aA.o: In function `main':
dreaming.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccTDg3AL.o:grader.c:(.text.startup+0x0): first defined here
/tmp/ccTDg3AL.o: In function `main':
grader.c:(.text.startup+0xa2): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status