#include "dreaming.h"
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
vector<pair<int, int>> voisins[100 * 1000];
bool estPasse[100 * 1000];
int diamDeb, diamFin, diamTaille = 0;
pair<int, int> calcDiam(int noeud, int parent = -1) {
estPasse[noeud] = true;
pair<int, int> melFeuille = {noeud, 0};
for(pair<int, int> voisin : voisins[noeud]) {
if(voisin.first == parent)
continue;
pair<int, int> resFeuille = calcDiam(voisin.first, noeud);
resFeuille.second += voisin.second;
if(resFeuille.second + melFeuille.second >= diamTaille) {
diamTaille = resFeuille.second + melFeuille.second;
diamDeb = resFeuille.first;
diamFin = melFeuille.first;
}
if(resFeuille.second > melFeuille.second) {
melFeuille = resFeuille;
}
}
return melFeuille;
}
bool calcChemin(int deb, int fin, vector<int>& chemin, int parent = -1) {
if(deb == fin)
return true;
for(pair<int, int> voisin : voisins[deb]) {
if(voisin.first == parent)
continue;
if(calcChemin(voisin.first, fin, chemin, deb)) {
chemin.push_back(voisin.second);
return true;
}
}
return false;
}
int travelTime(int nbVilles, int nbRoutes, int nouvTaille, int debs[], int fins[], int temps[]) {
for(int iRoute = 0;iRoute < nbRoutes;iRoute++) {
voisins[debs[iRoute]].push_back({fins[iRoute], temps[iRoute]});
voisins[fins[iRoute]].push_back({debs[iRoute], temps[iRoute]});
}
vector<int> rayons;
for(int iVille = 0;iVille < nbVilles;iVille++) {
if(estPasse[iVille])
continue;
diamTaille = 0;
diamDeb = diamFin = iVille;
calcDiam(iVille);
vector<int> chemin;
calcChemin(diamDeb, diamFin, chemin);
int somme = 0;
int rayon = diamTaille;
for(int val : chemin) {
somme += val;
rayon = min(rayon, max(somme, diamTaille - somme));
}
rayons.push_back(-rayon);
}
sort(rayons.begin(), rayons.end());
if(rayons.size() == 1)
return -rayons[0];
if(rayons.size() == 2) {
return nouvTaille - rayons[0] - rayons[1];
}
return max(nouvTaille - rayons[0] - rayons[1], 2 * nouvTaille - rayons[1] - rayons[2]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
15864 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
15864 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
15864 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
5504 KB |
Output is correct |
2 |
Correct |
24 ms |
5504 KB |
Output is correct |
3 |
Correct |
24 ms |
5496 KB |
Output is correct |
4 |
Correct |
25 ms |
5504 KB |
Output is correct |
5 |
Correct |
26 ms |
5496 KB |
Output is correct |
6 |
Correct |
25 ms |
5892 KB |
Output is correct |
7 |
Correct |
28 ms |
5624 KB |
Output is correct |
8 |
Correct |
25 ms |
5484 KB |
Output is correct |
9 |
Correct |
24 ms |
5376 KB |
Output is correct |
10 |
Correct |
27 ms |
5632 KB |
Output is correct |
11 |
Correct |
3 ms |
2688 KB |
Output is correct |
12 |
Correct |
7 ms |
3452 KB |
Output is correct |
13 |
Correct |
7 ms |
3452 KB |
Output is correct |
14 |
Correct |
6 ms |
3452 KB |
Output is correct |
15 |
Correct |
7 ms |
3452 KB |
Output is correct |
16 |
Correct |
7 ms |
3452 KB |
Output is correct |
17 |
Correct |
7 ms |
3452 KB |
Output is correct |
18 |
Correct |
6 ms |
3452 KB |
Output is correct |
19 |
Correct |
8 ms |
3452 KB |
Output is correct |
20 |
Correct |
3 ms |
2688 KB |
Output is correct |
21 |
Correct |
4 ms |
2688 KB |
Output is correct |
22 |
Correct |
4 ms |
2688 KB |
Output is correct |
23 |
Correct |
7 ms |
3452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
15864 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
15864 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |