답안 #286009

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
286009 2020-08-29T22:34:30 Z cjoa 꿈 (IOI13_dreaming) C++11
0 / 100
33 ms 2680 KB
#include "dreaming.h"

#include <vector>
#include <iostream>
#include <queue>
#include <cassert>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

struct Edge {
   int from, to, len;
};

#define MAXN 104
int NN;
vector<Edge> adj[MAXN];   // graph in adjacency list representation

void dfs(VI& visited, VI& comp, int u) {
   comp.push_back(u);
   visited[u] = true;
   for (Edge e : adj[u]) {
      if (visited[e.to]) continue;
      dfs(visited, comp, e.to);
   }
}

const int INF = 2000000010;
int get_longest_path() {
   int res = 0;
   for (int src = 0; src < NN; ++src) {
      queue<int> q;
      q.push(src);
      VI D(NN, INF);
      D[src] = 0;
      while (!q.empty()) {
         int u = q.front();
         q.pop();
         for (Edge e : adj[u]) {
            if (D[e.to] >= INF) {
               D[e.to] = D[u] + e.len;
               q.push(e.to);
            }
         }
      }

      int max_dist = 0;
      for (int v = 0; v < NN; ++v)
         max_dist = max(max_dist, D[v]);
      res = max(res, max_dist);
   }
   return res;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
   ::NN = N;

   assert( N <= 100 );

   for (int j = 0; j < M; ++j) {
      int u = A[j], v = B[j], len = T[j];
      adj[u].push_back({u, v, len});
      adj[v].push_back({v, u, len});
   }

   VVI components;

   VI visited(N, false);
   for (int u = 0; u < N; ++u) {
      if (!visited[u]) {
         VI comp;
         dfs(visited, comp, u);
      // for (int x : comp)
      //    cerr << x << ' ';
      // cerr << endl;
         components.push_back(comp);
      }
   }

   if ( components.size() > 2 )
      return rand();

   //assert( components.size() == 2 );

   VI& comp1 = components[0];
   VI& comp2 = components[1];

   int best_len = INF;
   for (int u : comp1) {
      for (int v : comp2) {
         adj[u].push_back({ u, v, L });
         adj[v].push_back({ v, u, L });

         int len = get_longest_path();
         best_len = min(best_len, len);
         
      // cerr << "Agregando edge " << u << "-> " << v
      //      << " longest path es " << len << endl;

         adj[u].pop_back();
         adj[v].pop_back();
      }
   }

   return best_len;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 2680 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 2680 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 2680 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 1280 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 2680 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 2680 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -