답안 #97684

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97684 2019-02-17T17:51:06 Z MiricaMatei 꿈 (IOI13_dreaming) C++14
47 / 100
93 ms 13220 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] = max(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 (i == 1) {
        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 60 ms 10488 KB Output is correct
2 Correct 61 ms 10204 KB Output is correct
3 Correct 41 ms 8568 KB Output is correct
4 Correct 11 ms 3840 KB Output is correct
5 Correct 10 ms 3456 KB Output is correct
6 Correct 17 ms 4480 KB Output is correct
7 Correct 4 ms 2816 KB Output is correct
8 Correct 29 ms 6008 KB Output is correct
9 Correct 37 ms 7416 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 52 ms 8440 KB Output is correct
12 Correct 60 ms 9336 KB Output is correct
13 Correct 4 ms 2812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 10488 KB Output is correct
2 Correct 61 ms 10204 KB Output is correct
3 Correct 41 ms 8568 KB Output is correct
4 Correct 11 ms 3840 KB Output is correct
5 Correct 10 ms 3456 KB Output is correct
6 Correct 17 ms 4480 KB Output is correct
7 Correct 4 ms 2816 KB Output is correct
8 Correct 29 ms 6008 KB Output is correct
9 Correct 37 ms 7416 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 52 ms 8440 KB Output is correct
12 Correct 60 ms 9336 KB Output is correct
13 Correct 4 ms 2812 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2688 KB Output is correct
16 Correct 4 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 4 ms 2688 KB Output is correct
19 Correct 4 ms 2688 KB Output is correct
20 Correct 3 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 3 ms 2688 KB Output is correct
23 Correct 4 ms 2688 KB Output is correct
24 Correct 4 ms 2688 KB Output is correct
25 Correct 4 ms 2688 KB Output is correct
26 Correct 4 ms 2688 KB Output is correct
27 Correct 4 ms 2688 KB Output is correct
28 Correct 4 ms 2688 KB Output is correct
29 Correct 4 ms 2688 KB Output is correct
30 Correct 4 ms 2688 KB Output is correct
31 Correct 4 ms 2688 KB Output is correct
32 Correct 4 ms 2688 KB Output is correct
33 Correct 4 ms 2688 KB Output is correct
34 Correct 4 ms 2688 KB Output is correct
35 Correct 4 ms 2688 KB Output is correct
36 Correct 4 ms 2688 KB Output is correct
37 Correct 4 ms 2688 KB Output is correct
38 Correct 4 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 10488 KB Output is correct
2 Correct 61 ms 10204 KB Output is correct
3 Correct 41 ms 8568 KB Output is correct
4 Correct 11 ms 3840 KB Output is correct
5 Correct 10 ms 3456 KB Output is correct
6 Correct 17 ms 4480 KB Output is correct
7 Correct 4 ms 2816 KB Output is correct
8 Correct 29 ms 6008 KB Output is correct
9 Correct 37 ms 7416 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 52 ms 8440 KB Output is correct
12 Correct 60 ms 9336 KB Output is correct
13 Correct 4 ms 2812 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2688 KB Output is correct
16 Correct 4 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 4 ms 2688 KB Output is correct
19 Correct 4 ms 2688 KB Output is correct
20 Correct 3 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 3 ms 2688 KB Output is correct
23 Correct 4 ms 2688 KB Output is correct
24 Correct 4 ms 2688 KB Output is correct
25 Correct 4 ms 2688 KB Output is correct
26 Correct 4 ms 2688 KB Output is correct
27 Correct 4 ms 2688 KB Output is correct
28 Correct 4 ms 2688 KB Output is correct
29 Correct 4 ms 2688 KB Output is correct
30 Correct 4 ms 2688 KB Output is correct
31 Correct 4 ms 2688 KB Output is correct
32 Correct 4 ms 2688 KB Output is correct
33 Correct 4 ms 2688 KB Output is correct
34 Correct 4 ms 2688 KB Output is correct
35 Correct 4 ms 2688 KB Output is correct
36 Correct 4 ms 2688 KB Output is correct
37 Correct 4 ms 2688 KB Output is correct
38 Correct 4 ms 2688 KB Output is correct
39 Correct 71 ms 10360 KB Output is correct
40 Correct 53 ms 10232 KB Output is correct
41 Correct 42 ms 8568 KB Output is correct
42 Correct 11 ms 3840 KB Output is correct
43 Correct 4 ms 2688 KB Output is correct
44 Correct 4 ms 2688 KB Output is correct
45 Correct 3 ms 2688 KB Output is correct
46 Correct 4 ms 2688 KB Output is correct
47 Correct 4 ms 2688 KB Output is correct
48 Correct 4 ms 2688 KB Output is correct
49 Correct 4 ms 2688 KB Output is correct
50 Correct 4 ms 2688 KB Output is correct
51 Correct 4 ms 2688 KB Output is correct
52 Correct 4 ms 2688 KB Output is correct
53 Correct 4 ms 2688 KB Output is correct
54 Correct 3 ms 2688 KB Output is correct
55 Correct 4 ms 2688 KB Output is correct
56 Correct 4 ms 2688 KB Output is correct
57 Correct 82 ms 9464 KB Output is correct
58 Correct 72 ms 9336 KB Output is correct
59 Correct 91 ms 9464 KB Output is correct
60 Correct 88 ms 9464 KB Output is correct
61 Correct 68 ms 9208 KB Output is correct
62 Correct 73 ms 9208 KB Output is correct
63 Correct 62 ms 9080 KB Output is correct
64 Correct 65 ms 9080 KB Output is correct
65 Correct 71 ms 9176 KB Output is correct
66 Correct 72 ms 9080 KB Output is correct
67 Correct 75 ms 9336 KB Output is correct
68 Correct 69 ms 9336 KB Output is correct
69 Correct 92 ms 9344 KB Output is correct
70 Correct 88 ms 9464 KB Output is correct
71 Correct 4 ms 2688 KB Output is correct
72 Correct 5 ms 2944 KB Output is correct
73 Correct 5 ms 2944 KB Output is correct
74 Correct 4 ms 2944 KB Output is correct
75 Correct 5 ms 2944 KB Output is correct
76 Correct 5 ms 2944 KB Output is correct
77 Correct 5 ms 2944 KB Output is correct
78 Correct 6 ms 2944 KB Output is correct
79 Correct 5 ms 2944 KB Output is correct
80 Correct 81 ms 9308 KB Output is correct
81 Correct 93 ms 9464 KB Output is correct
82 Correct 69 ms 9208 KB Output is correct
83 Correct 89 ms 9336 KB Output is correct
84 Correct 5 ms 2816 KB Output is correct
85 Correct 5 ms 2816 KB Output is correct
86 Correct 4 ms 2816 KB Output is correct
87 Correct 5 ms 2816 KB Output is correct
88 Correct 6 ms 2944 KB Output is correct
89 Correct 5 ms 2816 KB Output is correct
90 Correct 5 ms 2816 KB Output is correct
91 Correct 5 ms 2944 KB Output is correct
92 Correct 5 ms 2816 KB Output is correct
93 Correct 5 ms 2816 KB Output is correct
94 Correct 4 ms 2688 KB Output is correct
95 Correct 4 ms 2688 KB Output is correct
96 Correct 3 ms 2688 KB Output is correct
97 Correct 4 ms 2688 KB Output is correct
98 Correct 3 ms 2688 KB Output is correct
99 Correct 4 ms 2688 KB Output is correct
100 Correct 4 ms 2684 KB Output is correct
101 Correct 4 ms 2688 KB Output is correct
102 Correct 4 ms 2688 KB Output is correct
103 Correct 3 ms 2688 KB Output is correct
104 Correct 9 ms 3456 KB Output is correct
105 Correct 17 ms 4352 KB Output is correct
106 Correct 4 ms 2688 KB Output is correct
107 Correct 28 ms 5880 KB Output is correct
108 Correct 35 ms 7544 KB Output is correct
109 Correct 4 ms 2816 KB Output is correct
110 Correct 51 ms 8440 KB Output is correct
111 Correct 63 ms 9336 KB Output is correct
112 Correct 4 ms 2816 KB Output is correct
113 Correct 91 ms 13220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 6528 KB Output is correct
2 Incorrect 27 ms 6524 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 10488 KB Output is correct
2 Correct 61 ms 10204 KB Output is correct
3 Correct 41 ms 8568 KB Output is correct
4 Correct 11 ms 3840 KB Output is correct
5 Correct 10 ms 3456 KB Output is correct
6 Correct 17 ms 4480 KB Output is correct
7 Correct 4 ms 2816 KB Output is correct
8 Correct 29 ms 6008 KB Output is correct
9 Correct 37 ms 7416 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 52 ms 8440 KB Output is correct
12 Correct 60 ms 9336 KB Output is correct
13 Correct 4 ms 2812 KB Output is correct
14 Correct 4 ms 2816 KB Output is correct
15 Correct 4 ms 2816 KB Output is correct
16 Correct 5 ms 2944 KB Output is correct
17 Correct 5 ms 2816 KB Output is correct
18 Correct 4 ms 2816 KB Output is correct
19 Correct 5 ms 2944 KB Output is correct
20 Correct 5 ms 2816 KB Output is correct
21 Incorrect 4 ms 2816 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 10488 KB Output is correct
2 Correct 61 ms 10204 KB Output is correct
3 Correct 41 ms 8568 KB Output is correct
4 Correct 11 ms 3840 KB Output is correct
5 Correct 10 ms 3456 KB Output is correct
6 Correct 17 ms 4480 KB Output is correct
7 Correct 4 ms 2816 KB Output is correct
8 Correct 29 ms 6008 KB Output is correct
9 Correct 37 ms 7416 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 52 ms 8440 KB Output is correct
12 Correct 60 ms 9336 KB Output is correct
13 Correct 4 ms 2812 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2688 KB Output is correct
16 Correct 4 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 4 ms 2688 KB Output is correct
19 Correct 4 ms 2688 KB Output is correct
20 Correct 3 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 3 ms 2688 KB Output is correct
23 Correct 4 ms 2688 KB Output is correct
24 Correct 4 ms 2688 KB Output is correct
25 Correct 4 ms 2688 KB Output is correct
26 Correct 4 ms 2688 KB Output is correct
27 Correct 4 ms 2688 KB Output is correct
28 Correct 4 ms 2688 KB Output is correct
29 Correct 4 ms 2688 KB Output is correct
30 Correct 4 ms 2688 KB Output is correct
31 Correct 4 ms 2688 KB Output is correct
32 Correct 4 ms 2688 KB Output is correct
33 Correct 4 ms 2688 KB Output is correct
34 Correct 4 ms 2688 KB Output is correct
35 Correct 4 ms 2688 KB Output is correct
36 Correct 4 ms 2688 KB Output is correct
37 Correct 4 ms 2688 KB Output is correct
38 Correct 4 ms 2688 KB Output is correct
39 Correct 71 ms 10360 KB Output is correct
40 Correct 53 ms 10232 KB Output is correct
41 Correct 42 ms 8568 KB Output is correct
42 Correct 11 ms 3840 KB Output is correct
43 Correct 4 ms 2688 KB Output is correct
44 Correct 4 ms 2688 KB Output is correct
45 Correct 3 ms 2688 KB Output is correct
46 Correct 4 ms 2688 KB Output is correct
47 Correct 4 ms 2688 KB Output is correct
48 Correct 4 ms 2688 KB Output is correct
49 Correct 4 ms 2688 KB Output is correct
50 Correct 4 ms 2688 KB Output is correct
51 Correct 4 ms 2688 KB Output is correct
52 Correct 4 ms 2688 KB Output is correct
53 Correct 4 ms 2688 KB Output is correct
54 Correct 3 ms 2688 KB Output is correct
55 Correct 4 ms 2688 KB Output is correct
56 Correct 4 ms 2688 KB Output is correct
57 Correct 82 ms 9464 KB Output is correct
58 Correct 72 ms 9336 KB Output is correct
59 Correct 91 ms 9464 KB Output is correct
60 Correct 88 ms 9464 KB Output is correct
61 Correct 68 ms 9208 KB Output is correct
62 Correct 73 ms 9208 KB Output is correct
63 Correct 62 ms 9080 KB Output is correct
64 Correct 65 ms 9080 KB Output is correct
65 Correct 71 ms 9176 KB Output is correct
66 Correct 72 ms 9080 KB Output is correct
67 Correct 75 ms 9336 KB Output is correct
68 Correct 69 ms 9336 KB Output is correct
69 Correct 92 ms 9344 KB Output is correct
70 Correct 88 ms 9464 KB Output is correct
71 Correct 4 ms 2688 KB Output is correct
72 Correct 5 ms 2944 KB Output is correct
73 Correct 5 ms 2944 KB Output is correct
74 Correct 4 ms 2944 KB Output is correct
75 Correct 5 ms 2944 KB Output is correct
76 Correct 5 ms 2944 KB Output is correct
77 Correct 5 ms 2944 KB Output is correct
78 Correct 6 ms 2944 KB Output is correct
79 Correct 5 ms 2944 KB Output is correct
80 Correct 81 ms 9308 KB Output is correct
81 Correct 93 ms 9464 KB Output is correct
82 Correct 69 ms 9208 KB Output is correct
83 Correct 89 ms 9336 KB Output is correct
84 Correct 5 ms 2816 KB Output is correct
85 Correct 5 ms 2816 KB Output is correct
86 Correct 4 ms 2816 KB Output is correct
87 Correct 5 ms 2816 KB Output is correct
88 Correct 6 ms 2944 KB Output is correct
89 Correct 5 ms 2816 KB Output is correct
90 Correct 5 ms 2816 KB Output is correct
91 Correct 5 ms 2944 KB Output is correct
92 Correct 5 ms 2816 KB Output is correct
93 Correct 5 ms 2816 KB Output is correct
94 Correct 4 ms 2688 KB Output is correct
95 Correct 4 ms 2688 KB Output is correct
96 Correct 3 ms 2688 KB Output is correct
97 Correct 4 ms 2688 KB Output is correct
98 Correct 3 ms 2688 KB Output is correct
99 Correct 4 ms 2688 KB Output is correct
100 Correct 4 ms 2684 KB Output is correct
101 Correct 4 ms 2688 KB Output is correct
102 Correct 4 ms 2688 KB Output is correct
103 Correct 3 ms 2688 KB Output is correct
104 Correct 9 ms 3456 KB Output is correct
105 Correct 17 ms 4352 KB Output is correct
106 Correct 4 ms 2688 KB Output is correct
107 Correct 28 ms 5880 KB Output is correct
108 Correct 35 ms 7544 KB Output is correct
109 Correct 4 ms 2816 KB Output is correct
110 Correct 51 ms 8440 KB Output is correct
111 Correct 63 ms 9336 KB Output is correct
112 Correct 4 ms 2816 KB Output is correct
113 Correct 91 ms 13220 KB Output is correct
114 Correct 34 ms 6528 KB Output is correct
115 Incorrect 27 ms 6524 KB Output isn't correct
116 Halted 0 ms 0 KB -