답안 #97675

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97675 2019-02-17T17:36:34 Z MiricaMatei 꿈 (IOI13_dreaming) C++14
14 / 100
63 ms 10488 KB
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100000;

int d[MAXN + 5];
int c1[MAXN + 5], c2[MAXN + 5];
int m1[MAXN + 5], m2[MAXN + 5];
int viz[MAXN + 5];

vector<pair<int, int> >G[MAXN + 5];

void dfs1(int node) {
  viz[node] = 1;
  for (auto it:G[node])
    if (!viz[it.first]) {
      dfs1(it.first);
      c1[node] = max(c1[node], c1[it.first] + it.second);
    }
}

int dfs2(int node, int cUp) {
  viz[node] = 2;
  d[node] = max(c1[node], cUp);
  int ans = d[node];
  m1[0] = 0;
  for (int i = 0; i < G[node].size(); ++i) {
    int u = G[node][i].first;
    if (viz[u] == 2)
      m1[i + 1] = m1[i];
    else
      m1[i + 1] = max(m1[i], c1[u] + G[node][i].second);
  }
  m2[G[node].size()] = 0;
  for (int i = G[node].size() - 1; i >= 0; --i) {
    int u = G[node][i].first;
    if (viz[u] == 2)
      m2[i] = m2[i + 1];
    else
      m2[i] = max(m2[i + 1], c1[u] + G[node][i].second);
  }
  for (int i = 0; i < G[node].size(); ++i) {
    int u = G[node][i].first;
    if (viz[u] != 2)
      c2[u] = m1[i] + m2[i + 1];
  }
  for (int i = 0; i < G[node].size(); ++i) {
    int u = G[node][i].first;
    if (viz[u] != 2)
      ans = min(ans, dfs2(u, max(cUp, c2[u]) + G[node][i].second));
  }
  return ans;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
  for (int i = 0; i < M; ++i) {
    A[i]++;
    B[i]++;
    G[A[i]].push_back({B[i], T[i]});
    G[B[i]].push_back({A[i], T[i]});
  }

  int ans = 0, ll = 0;
  for (int i = 1; i <= N; ++i) {
    if (viz[i] == 0) {
      dfs1(i);
      int aux = dfs2(i, 0);
      if (ll == 0) {
        ans = ll = aux;
      } else {
        ans = max(ans, ll + L + aux);
        ll = min(max(ll, L + aux), max(aux, ll + L));
      }
    }
  }

  for (int i = 1; i <= N; ++i)
    ans = max(ans, d[i]);

  return ans;
}

/*int x[MAXN], y[MAXN], z[MAXN];

int main() {
  freopen("date.in", "r", stdin);
  freopen("date.out", "w", stdout);
  int n, m, l;
  scanf("%d%d%d", &n, &m, &l);
  for (int i = 0; i < m; ++i)
    scanf("%d%d%d", &x[i], &y[i], &z[i]);
  printf("%d\n", travelTime(n, m, l, x, y, z));
}
*/

Compilation message

dreaming.cpp: In function 'int dfs2(int, int)':
dreaming.cpp:29:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < G[node].size(); ++i) {
                   ~~^~~~~~~~~~~~~~~~
dreaming.cpp:44:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < G[node].size(); ++i) {
                   ~~^~~~~~~~~~~~~~~~
dreaming.cpp:49:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < G[node].size(); ++i) {
                   ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 10488 KB Output is correct
2 Correct 53 ms 10232 KB Output is correct
3 Correct 41 ms 8696 KB Output is correct
4 Correct 11 ms 3840 KB Output is correct
5 Correct 9 ms 3328 KB Output is correct
6 Correct 16 ms 4480 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 28 ms 6008 KB Output is correct
9 Correct 38 ms 7524 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 59 ms 8440 KB Output is correct
12 Correct 63 ms 9336 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 10488 KB Output is correct
2 Correct 53 ms 10232 KB Output is correct
3 Correct 41 ms 8696 KB Output is correct
4 Correct 11 ms 3840 KB Output is correct
5 Correct 9 ms 3328 KB Output is correct
6 Correct 16 ms 4480 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 28 ms 6008 KB Output is correct
9 Correct 38 ms 7524 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 59 ms 8440 KB Output is correct
12 Correct 63 ms 9336 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Incorrect 4 ms 2688 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 10488 KB Output is correct
2 Correct 53 ms 10232 KB Output is correct
3 Correct 41 ms 8696 KB Output is correct
4 Correct 11 ms 3840 KB Output is correct
5 Correct 9 ms 3328 KB Output is correct
6 Correct 16 ms 4480 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 28 ms 6008 KB Output is correct
9 Correct 38 ms 7524 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 59 ms 8440 KB Output is correct
12 Correct 63 ms 9336 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Incorrect 4 ms 2688 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 6528 KB Output is correct
2 Incorrect 25 ms 6440 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 10488 KB Output is correct
2 Correct 53 ms 10232 KB Output is correct
3 Correct 41 ms 8696 KB Output is correct
4 Correct 11 ms 3840 KB Output is correct
5 Correct 9 ms 3328 KB Output is correct
6 Correct 16 ms 4480 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 28 ms 6008 KB Output is correct
9 Correct 38 ms 7524 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 59 ms 8440 KB Output is correct
12 Correct 63 ms 9336 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Incorrect 5 ms 2816 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 10488 KB Output is correct
2 Correct 53 ms 10232 KB Output is correct
3 Correct 41 ms 8696 KB Output is correct
4 Correct 11 ms 3840 KB Output is correct
5 Correct 9 ms 3328 KB Output is correct
6 Correct 16 ms 4480 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 28 ms 6008 KB Output is correct
9 Correct 38 ms 7524 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 59 ms 8440 KB Output is correct
12 Correct 63 ms 9336 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Incorrect 4 ms 2688 KB Output isn't correct
16 Halted 0 ms 0 KB -