Submission #107822

# Submission time Handle Problem Language Result Execution time Memory
107822 2019-04-26T00:18:27 Z degelo Dreaming (IOI13_dreaming) C++17
0 / 100
127 ms 23948 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=raios[tam-3];
	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++){
               ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 127 ms 23948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 127 ms 23948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 127 ms 23948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 94 ms 16172 KB Output is correct
2 Correct 82 ms 16248 KB Output is correct
3 Correct 92 ms 16168 KB Output is correct
4 Correct 90 ms 16376 KB Output is correct
5 Correct 77 ms 16176 KB Output is correct
6 Correct 97 ms 17036 KB Output is correct
7 Correct 91 ms 16636 KB Output is correct
8 Correct 70 ms 16120 KB Output is correct
9 Correct 74 ms 15980 KB Output is correct
10 Correct 83 ms 16632 KB Output is correct
11 Correct 7 ms 7424 KB Output is correct
12 Correct 21 ms 13568 KB Output is correct
13 Correct 22 ms 13556 KB Output is correct
14 Correct 23 ms 13540 KB Output is correct
15 Correct 22 ms 13568 KB Output is correct
16 Correct 23 ms 13568 KB Output is correct
17 Correct 23 ms 13568 KB Output is correct
18 Correct 24 ms 13692 KB Output is correct
19 Correct 26 ms 13568 KB Output is correct
20 Incorrect 8 ms 7424 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 127 ms 23948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 127 ms 23948 KB Output isn't correct
2 Halted 0 ms 0 KB -