Submission #61262

# Submission time Handle Problem Language Result Execution time Memory
61262 2018-07-25T14:27:33 Z Flugan42 Dreaming (IOI13_dreaming) C++14
59 / 100
1000 ms 23224 KB
#include "dreaming.h"
#include <stdio.h>
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef long double lld;
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define per(i,a,b) for(ll i = a; i >= b; i--)
#define inf 1000000000000000000
#define all(x) x.begin(),x.end()
#define sz(x) (ll)(x).size()
#define trav(a,x) for(auto a : x)

vector<vii> e;
vii _,path,ans,comp;
vi vis2,mindist;
ll n,m;

ii bfs(ll v){
  priority_queue<ii> pq;
  pq.emplace(0,v);
  ll d,u,last,dist;
  mindist.assign(n,inf);
  mindist[v] = 0;
  while (!pq.empty()){
    d = -pq.top().first,u = pq.top().second; pq.pop();
    if (mindist[u] < d) continue;
    last = u; dist = d;
    rep(i,0,sz(e[u])){
      if (mindist[e[u][i].first] > d+e[u][i].second) {
        mindist[e[u][i].first] = d+e[u][i].second;
        pq.emplace(-d-e[u][i].second,e[u][i].first);
      }
    }
  }
  return make_pair(last,dist);
}

void dfs(ll v, ll target){
  if (vis2[v]) return;
  if (v == target) ans = path;
  vis2[v] = 1;
  rep(i,0,sz(e[v])){
    if (!vis2[e[v][i].first]){
      path.push_back(e[v][i]);
      dfs(e[v][i].first,target);
      path.pop_back();
    }
  }
}

ii center(ll u){
  ll fst = bfs(u).first;
  ii tmp = bfs(fst);
  ll snd = tmp.first, dist = tmp.second;
  //cout << " " << fst << " " << snd << " " << dist << endl;
  dfs(fst,snd);
  ll cur = 0;
  ll bestd = dist;
  rep(i,0,sz(ans)){
    cur += ans[i].second;
    if (max(cur,dist-cur) < bestd){
      bestd = max(cur,dist-cur);
    }
  }
  //cout << " " << best << " " << bestd << endl;
  return make_pair(bestd,dist);
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
  n = N; m = M;
  e.assign(n,_);
  rep(i,0,m){
    e[A[i]].emplace_back(B[i],T[i]);
    e[B[i]].emplace_back(A[i],T[i]);
  }
  vis2.assign(n,0);
  rep(i,0,n) {
    if (!vis2[i]) {
      comp.push_back(center(i));
    }
  }
  sort(all(comp)); reverse(all(comp));
  ll res = 0;
  rep(i,0,sz(comp)) res = max(res,comp[i].second);
  //rep(i,0,sz(comp)) cout << comp[i] << " "; cout << endl;
  if (sz(comp) == 1) return res;
  if (sz(comp) == 2) return max(comp[0].first+comp[1].first+L,res);
  return max(max(comp[0].first+comp[1].first+L,comp[1].first+comp[2].first+2*L),res);
}

Compilation message

dreaming.cpp: In function 'ii bfs(ll)':
dreaming.cpp:26:15: warning: 'dist' may be used uninitialized in this function [-Wmaybe-uninitialized]
   ll d,u,last,dist;
               ^~~~
dreaming.cpp:26:10: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
   ll d,u,last,dist;
          ^~~~
# Verdict Execution time Memory Grader output
1 Correct 74 ms 20840 KB Output is correct
2 Correct 68 ms 20840 KB Output is correct
3 Correct 48 ms 13732 KB Output is correct
4 Correct 12 ms 3452 KB Output is correct
5 Correct 9 ms 2176 KB Output is correct
6 Correct 18 ms 5112 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 32 ms 7920 KB Output is correct
9 Correct 44 ms 10608 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 63 ms 13552 KB Output is correct
12 Correct 78 ms 17380 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 20840 KB Output is correct
2 Correct 68 ms 20840 KB Output is correct
3 Correct 48 ms 13732 KB Output is correct
4 Correct 12 ms 3452 KB Output is correct
5 Correct 9 ms 2176 KB Output is correct
6 Correct 18 ms 5112 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 32 ms 7920 KB Output is correct
9 Correct 44 ms 10608 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 63 ms 13552 KB Output is correct
12 Correct 78 ms 17380 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 20840 KB Output is correct
2 Correct 68 ms 20840 KB Output is correct
3 Correct 48 ms 13732 KB Output is correct
4 Correct 12 ms 3452 KB Output is correct
5 Correct 9 ms 2176 KB Output is correct
6 Correct 18 ms 5112 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 32 ms 7920 KB Output is correct
9 Correct 44 ms 10608 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 63 ms 13552 KB Output is correct
12 Correct 78 ms 17380 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 90 ms 20836 KB Output is correct
40 Correct 72 ms 20840 KB Output is correct
41 Correct 47 ms 13804 KB Output is correct
42 Correct 10 ms 3452 KB Output is correct
43 Correct 2 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 2 ms 384 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 2 ms 384 KB Output is correct
49 Correct 2 ms 384 KB Output is correct
50 Correct 2 ms 384 KB Output is correct
51 Correct 2 ms 384 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 2 ms 384 KB Output is correct
54 Correct 2 ms 384 KB Output is correct
55 Correct 2 ms 384 KB Output is correct
56 Correct 2 ms 384 KB Output is correct
57 Correct 145 ms 11472 KB Output is correct
58 Correct 116 ms 11384 KB Output is correct
59 Correct 127 ms 11100 KB Output is correct
60 Correct 115 ms 11232 KB Output is correct
61 Correct 131 ms 10972 KB Output is correct
62 Correct 134 ms 10948 KB Output is correct
63 Correct 142 ms 11060 KB Output is correct
64 Correct 150 ms 11036 KB Output is correct
65 Correct 116 ms 11000 KB Output is correct
66 Correct 136 ms 11136 KB Output is correct
67 Correct 120 ms 11132 KB Output is correct
68 Correct 127 ms 11128 KB Output is correct
69 Correct 115 ms 11300 KB Output is correct
70 Correct 104 ms 11248 KB Output is correct
71 Correct 2 ms 256 KB Output is correct
72 Correct 4 ms 640 KB Output is correct
73 Correct 4 ms 640 KB Output is correct
74 Correct 4 ms 640 KB Output is correct
75 Correct 4 ms 640 KB Output is correct
76 Correct 4 ms 640 KB Output is correct
77 Correct 4 ms 640 KB Output is correct
78 Correct 4 ms 768 KB Output is correct
79 Correct 4 ms 640 KB Output is correct
80 Correct 135 ms 11128 KB Output is correct
81 Correct 145 ms 11256 KB Output is correct
82 Correct 115 ms 11000 KB Output is correct
83 Correct 141 ms 10872 KB Output is correct
84 Correct 3 ms 640 KB Output is correct
85 Correct 3 ms 512 KB Output is correct
86 Correct 4 ms 640 KB Output is correct
87 Correct 4 ms 640 KB Output is correct
88 Correct 4 ms 640 KB Output is correct
89 Correct 4 ms 640 KB Output is correct
90 Correct 4 ms 640 KB Output is correct
91 Correct 4 ms 768 KB Output is correct
92 Correct 4 ms 640 KB Output is correct
93 Correct 4 ms 640 KB Output is correct
94 Correct 2 ms 384 KB Output is correct
95 Correct 2 ms 384 KB Output is correct
96 Correct 2 ms 384 KB Output is correct
97 Correct 2 ms 384 KB Output is correct
98 Correct 2 ms 384 KB Output is correct
99 Correct 2 ms 384 KB Output is correct
100 Correct 4 ms 384 KB Output is correct
101 Correct 2 ms 384 KB Output is correct
102 Correct 2 ms 384 KB Output is correct
103 Correct 2 ms 384 KB Output is correct
104 Correct 10 ms 2176 KB Output is correct
105 Correct 18 ms 5112 KB Output is correct
106 Correct 2 ms 384 KB Output is correct
107 Correct 36 ms 7928 KB Output is correct
108 Correct 47 ms 10672 KB Output is correct
109 Correct 2 ms 512 KB Output is correct
110 Correct 66 ms 13680 KB Output is correct
111 Correct 83 ms 17384 KB Output is correct
112 Correct 3 ms 512 KB Output is correct
113 Correct 114 ms 23224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1059 ms 6652 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 74 ms 20840 KB Output is correct
2 Correct 68 ms 20840 KB Output is correct
3 Correct 48 ms 13732 KB Output is correct
4 Correct 12 ms 3452 KB Output is correct
5 Correct 9 ms 2176 KB Output is correct
6 Correct 18 ms 5112 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 32 ms 7920 KB Output is correct
9 Correct 44 ms 10608 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 63 ms 13552 KB Output is correct
12 Correct 78 ms 17380 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 4 ms 640 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 4 ms 640 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 4 ms 640 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 2 ms 256 KB Output is correct
41 Correct 2 ms 256 KB Output is correct
42 Correct 4 ms 1068 KB Output is correct
43 Correct 4 ms 1024 KB Output is correct
44 Correct 6 ms 640 KB Output is correct
45 Correct 8 ms 640 KB Output is correct
46 Correct 4 ms 640 KB Output is correct
47 Correct 4 ms 640 KB Output is correct
48 Correct 7 ms 676 KB Output is correct
49 Correct 8 ms 640 KB Output is correct
50 Correct 3 ms 640 KB Output is correct
51 Correct 4 ms 768 KB Output is correct
52 Correct 9 ms 512 KB Output is correct
53 Correct 6 ms 640 KB Output is correct
54 Correct 4 ms 640 KB Output is correct
55 Correct 4 ms 640 KB Output is correct
56 Correct 5 ms 640 KB Output is correct
57 Correct 6 ms 640 KB Output is correct
58 Correct 8 ms 668 KB Output is correct
59 Correct 7 ms 512 KB Output is correct
60 Correct 4 ms 640 KB Output is correct
61 Correct 4 ms 640 KB Output is correct
62 Correct 5 ms 640 KB Output is correct
63 Correct 4 ms 640 KB Output is correct
64 Correct 4 ms 768 KB Output is correct
65 Correct 4 ms 640 KB Output is correct
66 Correct 7 ms 640 KB Output is correct
67 Correct 7 ms 640 KB Output is correct
68 Correct 9 ms 640 KB Output is correct
69 Correct 9 ms 640 KB Output is correct
70 Correct 5 ms 640 KB Output is correct
71 Correct 5 ms 640 KB Output is correct
72 Correct 8 ms 640 KB Output is correct
73 Correct 9 ms 640 KB Output is correct
74 Correct 6 ms 640 KB Output is correct
75 Correct 4 ms 640 KB Output is correct
76 Correct 6 ms 640 KB Output is correct
77 Correct 6 ms 640 KB Output is correct
78 Correct 7 ms 640 KB Output is correct
79 Correct 7 ms 512 KB Output is correct
80 Correct 3 ms 640 KB Output is correct
81 Correct 3 ms 640 KB Output is correct
82 Correct 4 ms 640 KB Output is correct
83 Correct 3 ms 640 KB Output is correct
84 Correct 4 ms 640 KB Output is correct
85 Correct 4 ms 640 KB Output is correct
86 Correct 4 ms 640 KB Output is correct
87 Correct 4 ms 640 KB Output is correct
88 Correct 4 ms 640 KB Output is correct
89 Correct 4 ms 640 KB Output is correct
90 Correct 2 ms 384 KB Output is correct
91 Correct 2 ms 384 KB Output is correct
92 Correct 2 ms 384 KB Output is correct
93 Correct 2 ms 384 KB Output is correct
94 Correct 2 ms 384 KB Output is correct
95 Correct 2 ms 384 KB Output is correct
96 Correct 2 ms 384 KB Output is correct
97 Correct 2 ms 384 KB Output is correct
98 Correct 2 ms 384 KB Output is correct
99 Correct 2 ms 384 KB Output is correct
100 Correct 2 ms 384 KB Output is correct
101 Correct 2 ms 512 KB Output is correct
102 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 20840 KB Output is correct
2 Correct 68 ms 20840 KB Output is correct
3 Correct 48 ms 13732 KB Output is correct
4 Correct 12 ms 3452 KB Output is correct
5 Correct 9 ms 2176 KB Output is correct
6 Correct 18 ms 5112 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 32 ms 7920 KB Output is correct
9 Correct 44 ms 10608 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 63 ms 13552 KB Output is correct
12 Correct 78 ms 17380 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 90 ms 20836 KB Output is correct
40 Correct 72 ms 20840 KB Output is correct
41 Correct 47 ms 13804 KB Output is correct
42 Correct 10 ms 3452 KB Output is correct
43 Correct 2 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 2 ms 384 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 2 ms 384 KB Output is correct
49 Correct 2 ms 384 KB Output is correct
50 Correct 2 ms 384 KB Output is correct
51 Correct 2 ms 384 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 2 ms 384 KB Output is correct
54 Correct 2 ms 384 KB Output is correct
55 Correct 2 ms 384 KB Output is correct
56 Correct 2 ms 384 KB Output is correct
57 Correct 145 ms 11472 KB Output is correct
58 Correct 116 ms 11384 KB Output is correct
59 Correct 127 ms 11100 KB Output is correct
60 Correct 115 ms 11232 KB Output is correct
61 Correct 131 ms 10972 KB Output is correct
62 Correct 134 ms 10948 KB Output is correct
63 Correct 142 ms 11060 KB Output is correct
64 Correct 150 ms 11036 KB Output is correct
65 Correct 116 ms 11000 KB Output is correct
66 Correct 136 ms 11136 KB Output is correct
67 Correct 120 ms 11132 KB Output is correct
68 Correct 127 ms 11128 KB Output is correct
69 Correct 115 ms 11300 KB Output is correct
70 Correct 104 ms 11248 KB Output is correct
71 Correct 2 ms 256 KB Output is correct
72 Correct 4 ms 640 KB Output is correct
73 Correct 4 ms 640 KB Output is correct
74 Correct 4 ms 640 KB Output is correct
75 Correct 4 ms 640 KB Output is correct
76 Correct 4 ms 640 KB Output is correct
77 Correct 4 ms 640 KB Output is correct
78 Correct 4 ms 768 KB Output is correct
79 Correct 4 ms 640 KB Output is correct
80 Correct 135 ms 11128 KB Output is correct
81 Correct 145 ms 11256 KB Output is correct
82 Correct 115 ms 11000 KB Output is correct
83 Correct 141 ms 10872 KB Output is correct
84 Correct 3 ms 640 KB Output is correct
85 Correct 3 ms 512 KB Output is correct
86 Correct 4 ms 640 KB Output is correct
87 Correct 4 ms 640 KB Output is correct
88 Correct 4 ms 640 KB Output is correct
89 Correct 4 ms 640 KB Output is correct
90 Correct 4 ms 640 KB Output is correct
91 Correct 4 ms 768 KB Output is correct
92 Correct 4 ms 640 KB Output is correct
93 Correct 4 ms 640 KB Output is correct
94 Correct 2 ms 384 KB Output is correct
95 Correct 2 ms 384 KB Output is correct
96 Correct 2 ms 384 KB Output is correct
97 Correct 2 ms 384 KB Output is correct
98 Correct 2 ms 384 KB Output is correct
99 Correct 2 ms 384 KB Output is correct
100 Correct 4 ms 384 KB Output is correct
101 Correct 2 ms 384 KB Output is correct
102 Correct 2 ms 384 KB Output is correct
103 Correct 2 ms 384 KB Output is correct
104 Correct 10 ms 2176 KB Output is correct
105 Correct 18 ms 5112 KB Output is correct
106 Correct 2 ms 384 KB Output is correct
107 Correct 36 ms 7928 KB Output is correct
108 Correct 47 ms 10672 KB Output is correct
109 Correct 2 ms 512 KB Output is correct
110 Correct 66 ms 13680 KB Output is correct
111 Correct 83 ms 17384 KB Output is correct
112 Correct 3 ms 512 KB Output is correct
113 Correct 114 ms 23224 KB Output is correct
114 Execution timed out 1059 ms 6652 KB Time limit exceeded
115 Halted 0 ms 0 KB -