Submission #61259

# Submission time Handle Problem Language Result Execution time Memory
61259 2018-07-25T14:22:10 Z Flugan42 Dreaming (IOI13_dreaming) C++14
59 / 100
1000 ms 23272 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 vis,vis2;
ll n,m;

ii bfs(ll v){
  priority_queue<ii> pq;
  pq.emplace(0,v);
  ll d,u,last,dist;
  vis.assign(n,0);
  while (!pq.empty()){
    d = -pq.top().first,u = pq.top().second; pq.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    last = u; dist = d;
    rep(i,0,sz(e[u])){
      if (!vis[e[u][i].first]) 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 86 ms 20840 KB Output is correct
2 Correct 80 ms 20736 KB Output is correct
3 Correct 48 ms 13804 KB Output is correct
4 Correct 11 ms 3480 KB Output is correct
5 Correct 9 ms 2048 KB Output is correct
6 Correct 18 ms 5112 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 34 ms 7920 KB Output is correct
9 Correct 42 ms 10608 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 72 ms 13552 KB Output is correct
12 Correct 89 ms 17384 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 20840 KB Output is correct
2 Correct 80 ms 20736 KB Output is correct
3 Correct 48 ms 13804 KB Output is correct
4 Correct 11 ms 3480 KB Output is correct
5 Correct 9 ms 2048 KB Output is correct
6 Correct 18 ms 5112 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 34 ms 7920 KB Output is correct
9 Correct 42 ms 10608 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 72 ms 13552 KB Output is correct
12 Correct 89 ms 17384 KB Output is correct
13 Correct 3 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 428 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 408 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 256 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 86 ms 20840 KB Output is correct
2 Correct 80 ms 20736 KB Output is correct
3 Correct 48 ms 13804 KB Output is correct
4 Correct 11 ms 3480 KB Output is correct
5 Correct 9 ms 2048 KB Output is correct
6 Correct 18 ms 5112 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 34 ms 7920 KB Output is correct
9 Correct 42 ms 10608 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 72 ms 13552 KB Output is correct
12 Correct 89 ms 17384 KB Output is correct
13 Correct 3 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 428 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 408 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 256 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 75 ms 20788 KB Output is correct
40 Correct 86 ms 20840 KB Output is correct
41 Correct 52 ms 13804 KB Output is correct
42 Correct 11 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 141 ms 11512 KB Output is correct
58 Correct 132 ms 11340 KB Output is correct
59 Correct 122 ms 11332 KB Output is correct
60 Correct 131 ms 11256 KB Output is correct
61 Correct 121 ms 10956 KB Output is correct
62 Correct 130 ms 11000 KB Output is correct
63 Correct 145 ms 11028 KB Output is correct
64 Correct 133 ms 11000 KB Output is correct
65 Correct 123 ms 11000 KB Output is correct
66 Correct 139 ms 11148 KB Output is correct
67 Correct 149 ms 11228 KB Output is correct
68 Correct 139 ms 11140 KB Output is correct
69 Correct 124 ms 11256 KB Output is correct
70 Correct 135 ms 11256 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 768 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 640 KB Output is correct
79 Correct 4 ms 640 KB Output is correct
80 Correct 157 ms 11128 KB Output is correct
81 Correct 143 ms 11100 KB Output is correct
82 Correct 148 ms 10988 KB Output is correct
83 Correct 139 ms 10872 KB Output is correct
84 Correct 3 ms 640 KB Output is correct
85 Correct 4 ms 640 KB Output is correct
86 Correct 3 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 3 ms 640 KB Output is correct
91 Correct 4 ms 640 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 2 ms 384 KB Output is correct
101 Correct 2 ms 384 KB Output is correct
102 Correct 3 ms 384 KB Output is correct
103 Correct 2 ms 384 KB Output is correct
104 Correct 9 ms 2176 KB Output is correct
105 Correct 19 ms 5112 KB Output is correct
106 Correct 2 ms 384 KB Output is correct
107 Correct 32 ms 7920 KB Output is correct
108 Correct 46 ms 10736 KB Output is correct
109 Correct 3 ms 512 KB Output is correct
110 Correct 64 ms 13612 KB Output is correct
111 Correct 77 ms 17276 KB Output is correct
112 Correct 2 ms 512 KB Output is correct
113 Correct 127 ms 23272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 6844 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 86 ms 20840 KB Output is correct
2 Correct 80 ms 20736 KB Output is correct
3 Correct 48 ms 13804 KB Output is correct
4 Correct 11 ms 3480 KB Output is correct
5 Correct 9 ms 2048 KB Output is correct
6 Correct 18 ms 5112 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 34 ms 7920 KB Output is correct
9 Correct 42 ms 10608 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 72 ms 13552 KB Output is correct
12 Correct 89 ms 17384 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 4 ms 512 KB Output is correct
19 Correct 4 ms 640 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 5 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 2 ms 512 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 384 KB Output is correct
41 Correct 2 ms 256 KB Output is correct
42 Correct 4 ms 1024 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 5 ms 768 KB Output is correct
47 Correct 4 ms 684 KB Output is correct
48 Correct 7 ms 640 KB Output is correct
49 Correct 8 ms 640 KB Output is correct
50 Correct 4 ms 640 KB Output is correct
51 Correct 4 ms 768 KB Output is correct
52 Correct 9 ms 640 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 6 ms 640 KB Output is correct
57 Correct 5 ms 640 KB Output is correct
58 Correct 7 ms 640 KB Output is correct
59 Correct 7 ms 640 KB Output is correct
60 Correct 4 ms 640 KB Output is correct
61 Correct 5 ms 640 KB Output is correct
62 Correct 4 ms 640 KB Output is correct
63 Correct 5 ms 640 KB Output is correct
64 Correct 4 ms 640 KB Output is correct
65 Correct 4 ms 640 KB Output is correct
66 Correct 7 ms 640 KB Output is correct
67 Correct 8 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 6 ms 640 KB Output is correct
71 Correct 4 ms 640 KB Output is correct
72 Correct 8 ms 640 KB Output is correct
73 Correct 9 ms 512 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 640 KB Output is correct
80 Correct 3 ms 640 KB Output is correct
81 Correct 4 ms 640 KB Output is correct
82 Correct 3 ms 640 KB Output is correct
83 Correct 3 ms 640 KB Output is correct
84 Correct 3 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 3 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 86 ms 20840 KB Output is correct
2 Correct 80 ms 20736 KB Output is correct
3 Correct 48 ms 13804 KB Output is correct
4 Correct 11 ms 3480 KB Output is correct
5 Correct 9 ms 2048 KB Output is correct
6 Correct 18 ms 5112 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 34 ms 7920 KB Output is correct
9 Correct 42 ms 10608 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 72 ms 13552 KB Output is correct
12 Correct 89 ms 17384 KB Output is correct
13 Correct 3 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 428 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 408 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 256 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 75 ms 20788 KB Output is correct
40 Correct 86 ms 20840 KB Output is correct
41 Correct 52 ms 13804 KB Output is correct
42 Correct 11 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 141 ms 11512 KB Output is correct
58 Correct 132 ms 11340 KB Output is correct
59 Correct 122 ms 11332 KB Output is correct
60 Correct 131 ms 11256 KB Output is correct
61 Correct 121 ms 10956 KB Output is correct
62 Correct 130 ms 11000 KB Output is correct
63 Correct 145 ms 11028 KB Output is correct
64 Correct 133 ms 11000 KB Output is correct
65 Correct 123 ms 11000 KB Output is correct
66 Correct 139 ms 11148 KB Output is correct
67 Correct 149 ms 11228 KB Output is correct
68 Correct 139 ms 11140 KB Output is correct
69 Correct 124 ms 11256 KB Output is correct
70 Correct 135 ms 11256 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 768 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 640 KB Output is correct
79 Correct 4 ms 640 KB Output is correct
80 Correct 157 ms 11128 KB Output is correct
81 Correct 143 ms 11100 KB Output is correct
82 Correct 148 ms 10988 KB Output is correct
83 Correct 139 ms 10872 KB Output is correct
84 Correct 3 ms 640 KB Output is correct
85 Correct 4 ms 640 KB Output is correct
86 Correct 3 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 3 ms 640 KB Output is correct
91 Correct 4 ms 640 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 2 ms 384 KB Output is correct
101 Correct 2 ms 384 KB Output is correct
102 Correct 3 ms 384 KB Output is correct
103 Correct 2 ms 384 KB Output is correct
104 Correct 9 ms 2176 KB Output is correct
105 Correct 19 ms 5112 KB Output is correct
106 Correct 2 ms 384 KB Output is correct
107 Correct 32 ms 7920 KB Output is correct
108 Correct 46 ms 10736 KB Output is correct
109 Correct 3 ms 512 KB Output is correct
110 Correct 64 ms 13612 KB Output is correct
111 Correct 77 ms 17276 KB Output is correct
112 Correct 2 ms 512 KB Output is correct
113 Correct 127 ms 23272 KB Output is correct
114 Execution timed out 1070 ms 6844 KB Time limit exceeded
115 Halted 0 ms 0 KB -