답안 #284768

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
284768 2020-08-28T02:36:34 Z cjoa 꿈 (IOI13_dreaming) C++11
14 / 100
62 ms 15472 KB
#include "dreaming.h"
#include <vector>
#include <algorithm>
#include <cassert>
#include <iostream>
#include <cstdlib>

using namespace std;

typedef vector<int> VI;
typedef long long llong;
typedef pair<llong,llong> PLL;

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;

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

   PLL res(INF, INF);
   llong sum_cur_dist = 0;
   for (Edge e : path) {
      sum_cur_dist += e.len;
      PLL cur(sum_cur_dist, sum_dist - sum_cur_dist);
      if (cur.first < cur.second)
         swap(cur.first, cur.second);
      res = min(res, cur);
   }
   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;
         assert(deg[u] != 0);

         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);

      PLL center_dist1 = get_center_distances(paths[0]);
      PLL center_dist2 = get_center_distances(paths[1]);

   // cerr << "L:" << L << endl;
   // cerr << center_dist1.first << ' ' << center_dist1.second << endl;
   // cerr << center_dist2.first << ' ' << center_dist2.second << endl;

      llong res = max(center_dist1.first + center_dist1.second,
                      center_dist2.first + center_dist2.second);

      res = max(res, center_dist1.first + L + center_dist2.first);
      return res;

   }

   assert(false);
   return 1 + rand();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 15472 KB Output is correct
2 Correct 58 ms 15472 KB Output is correct
3 Correct 38 ms 10220 KB Output is correct
4 Correct 8 ms 2560 KB Output is correct
5 Correct 6 ms 1664 KB Output is correct
6 Correct 13 ms 3708 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 25 ms 5616 KB Output is correct
9 Correct 34 ms 7784 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 58 ms 11208 KB Output is correct
12 Correct 62 ms 13720 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 15472 KB Output is correct
2 Correct 58 ms 15472 KB Output is correct
3 Correct 38 ms 10220 KB Output is correct
4 Correct 8 ms 2560 KB Output is correct
5 Correct 6 ms 1664 KB Output is correct
6 Correct 13 ms 3708 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 25 ms 5616 KB Output is correct
9 Correct 34 ms 7784 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 58 ms 11208 KB Output is correct
12 Correct 62 ms 13720 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Runtime error 2 ms 512 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 15472 KB Output is correct
2 Correct 58 ms 15472 KB Output is correct
3 Correct 38 ms 10220 KB Output is correct
4 Correct 8 ms 2560 KB Output is correct
5 Correct 6 ms 1664 KB Output is correct
6 Correct 13 ms 3708 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 25 ms 5616 KB Output is correct
9 Correct 34 ms 7784 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 58 ms 11208 KB Output is correct
12 Correct 62 ms 13720 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Runtime error 2 ms 512 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 25 ms 10360 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 15472 KB Output is correct
2 Correct 58 ms 15472 KB Output is correct
3 Correct 38 ms 10220 KB Output is correct
4 Correct 8 ms 2560 KB Output is correct
5 Correct 6 ms 1664 KB Output is correct
6 Correct 13 ms 3708 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 25 ms 5616 KB Output is correct
9 Correct 34 ms 7784 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 58 ms 11208 KB Output is correct
12 Correct 62 ms 13720 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Runtime error 2 ms 640 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 15472 KB Output is correct
2 Correct 58 ms 15472 KB Output is correct
3 Correct 38 ms 10220 KB Output is correct
4 Correct 8 ms 2560 KB Output is correct
5 Correct 6 ms 1664 KB Output is correct
6 Correct 13 ms 3708 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 25 ms 5616 KB Output is correct
9 Correct 34 ms 7784 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 58 ms 11208 KB Output is correct
12 Correct 62 ms 13720 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Runtime error 2 ms 512 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -