Submission #284749

# Submission time Handle Problem Language Result Execution time Memory
284749 2020-08-28T01:56:24 Z cjoa Dreaming (IOI13_dreaming) C++11
0 / 100
63 ms 15472 KB
#include "dreaming.h"
#include <vector>
#include <cassert>
#include <iostream>
#include <cstdlib>

using namespace std;

typedef vector<int> VI;
typedef long long llong;

struct Edge {
   int to, len;
};

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

bool is_subtask1(int N, int M, int A[], int B[], int T[], VI& deg) {
   if (M != N-2) return false;
   deg.assign(N, 0);
   for (int j = 0; j < M; ++j) {
      int u = A[j], v = B[j];
      ++deg[u];
      ++deg[v];
   }
   for (int u = 0; u < N; ++u)
      if (deg[u] > 2)
         return false;
   return true;
}

void dfs(const vector< vector<Edge> >& G,
         vector<bool>& vis,
         vector<Edge>& path,
         int u) {
   vis[u] = true;
   for (Edge e : G[u]) {
      if (vis[e.to]) continue;
      path.push_back(e);
      dfs(G, vis, path, e.to);
   }
}

const llong INF = 1e18;

llong get_center_dist(const vector<Edge>& path) {
   llong sum_dist = 0;
   for (Edge e : path)
      sum_dist += e.len;

   llong res = INF;
   llong sum_cur_dist = 0;
   for (Edge e : path) {
      sum_cur_dist += e.len;
      res = min(res, max(sum_cur_dist, sum_dist - sum_cur_dist));
   }
   return res;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
   vector< vector<Edge> > G = extract_graph(N, M, A, B, T);

   VI deg(N);
   if (is_subtask1(N, M, A, B, T, deg)) {
      vector<bool> vis(N, false);
      vector< vector<Edge> > paths;
      for (int u = 0; u < N; ++u) {
         if (vis[u]) continue;
         if (deg[u] == 2) continue;
         vector<Edge> path;
         dfs(G, vis, path, u);
         paths.push_back(path);

         /*
         cerr << u;
         for (Edge e : path)
            cerr << " --{" << e.len << "}-- " << e.to;
         cerr << endl;
         */
      }

      assert(paths.size() == 2);

      llong center_dist1 = get_center_dist(paths[0]);
      llong center_dist2 = get_center_dist(paths[1]);

      llong res1 = max(center_dist1, L + center_dist2);
      llong res2 = max(L + center_dist1, center_dist2);
      return min(res1, res2);
   }

   assert(false);
   return 1 + rand();
}
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 15472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 15472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 15472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 25 ms 10368 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 15472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 15472 KB Output isn't correct
2 Halted 0 ms 0 KB -