답안 #110177

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
110177 2019-05-09T19:10:04 Z Arturgo 꿈 (IOI13_dreaming) C++14
18 / 100
63 ms 15864 KB
#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, sommeBef = 0;
    for(int val : chemin) {
      sommeBef = somme;
      somme += val;
      if(2 * somme >= diamTaille)
	break;
    }

    int rayon = min(max(sommeBef, diamTaille - sommeBef), 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]);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 15864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 15864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 15864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 5504 KB Output is correct
2 Correct 29 ms 5576 KB Output is correct
3 Correct 25 ms 5496 KB Output is correct
4 Correct 28 ms 5504 KB Output is correct
5 Correct 29 ms 5504 KB Output is correct
6 Correct 29 ms 5888 KB Output is correct
7 Correct 25 ms 5632 KB Output is correct
8 Correct 25 ms 5504 KB Output is correct
9 Correct 27 ms 5504 KB Output is correct
10 Correct 26 ms 5628 KB Output is correct
11 Correct 4 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 7 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 7 ms 3452 KB Output is correct
19 Correct 6 ms 3452 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
21 Correct 3 ms 2688 KB Output is correct
22 Correct 3 ms 2688 KB Output is correct
23 Correct 6 ms 3452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 15864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 15864 KB Output isn't correct
2 Halted 0 ms 0 KB -