답안 #104072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104072 2019-04-03T23:08:39 Z pedro_sponchiado 꿈 (IOI13_dreaming) C++17
0 / 100
87 ms 30328 KB
#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010;

int n, m, l;
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, maior2;
	for(int i=0; i<n; i++){
		if(maxi<dist[i]){
			maior1=i;
			maxi=dist[i];
		}
	}
	
	dist[maior1]=0;
	dfs(maior1);
	maxi=0;
	for(int i=0; i<n; i++){
		if(maxi<dist[i]){
			maior2=i;
			maxi=dist[i];
		}
	}
	
	int at=maior2;
	pair<int, int> resp=make_pair(0, dist[maior2]);
	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[maxn], int B[maxn], int T[maxn]) {
    
    n=N; m=M; l=L;
    
    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:16: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:49:47: warning: 'maior2' may be used uninitialized in this function [-Wmaybe-uninitialized]
  pair<int, int> resp=make_pair(0, dist[maior2]);
                                               ^
dreaming.cpp:32:3: warning: 'maxi' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if(maxi<dist[i]){
   ^~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 87 ms 30328 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 87 ms 30328 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 87 ms 30328 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 37 ms 18424 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 87 ms 30328 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 87 ms 30328 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -