Submission #546807

# Submission time Handle Problem Language Result Execution time Memory
546807 2022-04-08T14:15:16 Z drkarlicio2107 Dreaming (IOI13_dreaming) C++14
0 / 100
64 ms 65536 KB
// code by: Karlo Brcic
// Dreaming, IOI 2013
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std; 
//int A [100010], B [100010], T [100010];
vector < pair <int, int> > g [100010];
int bio [100010];
vector <int> rad; vector < pair <int, int> > red;
int maxi=-1, maxi2=0;
int dfs (int x, int par, int zapis, int tre){ // returns the furtherest point from x
	int ans=0; bio [x]=1; int tko=-1; int dulj=-1;
	if (tre>maxi){
		maxi=tre; maxi2=x;
	}
	for (int i=0; i<g[x].size(); i++){
		int y=g[x][i].first; int b=dfs (y, x, zapis, tre+g[x][i].second)+g[x][i].second;
		if (y==par) continue;
		if (ans<b){
			ans=b;
			tko=y; dulj=g[x][i].second;
		}
	}
	if (tko!=-1 && zapis){
		red.push_back ({tko, dulj});
	}
	//cout << x << " " << ans << endl;
	return ans;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]){
	for (int i=0; i<M; i++){
		int a=A [i];
		int b=B [i];
		int c=T [i];
		g [a].push_back ({b, c});
		g [b].push_back ({a, c});
	}
	for (int i=0; i<N; i++){
		if (bio [i]) continue;
		red.clear();
		maxi=-1;
		int fur1=dfs (i, -1, 0, 0);
		maxi=-1;
		int fur2=dfs (maxi2, -1, 1, 0);
		reverse (red.begin(), red.end());
		int tre=0; int r=fur2;
		for (int j=0; j<red.size(); j++){
			tre+=red[j].second;
			r=min (r, max (tre, fur2-tre));
		}
		rad.push_back (r);
		//cout << fur2 << endl;
	}
	sort (rad.rbegin(), rad.rend());
	int ans=rad [0];
	if (rad.size()>=2){
		ans=max (ans, rad [0]+rad[1]+L);
	}
	if (rad.size()>=3){
		ans=max (ans, rad [1]+rad[2]+2*L);
	}
	return ans;
}
/*int main (){
	int n, m, l; cin >> n >> m >> l;
	for (int i=0; i<m; i++) cin >> A [i] >> B [i] >> T [i];
	cout << travelTime (n, m, l, A, B, T);
	return 0;
}*/

Compilation message

dreaming.cpp: In function 'int dfs(int, int, int, int)':
dreaming.cpp:16:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  for (int i=0; i<g[x].size(); i++){
      |                ~^~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:47:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for (int j=0; j<red.size(); j++){
      |                 ~^~~~~~~~~~~
dreaming.cpp:42:7: warning: unused variable 'fur1' [-Wunused-variable]
   42 |   int fur1=dfs (i, -1, 0, 0);
      |       ^~~~
# Verdict Execution time Memory Grader output
1 Runtime error 64 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 41 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 64 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 50 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 41 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 64 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -