Submission #757754

# Submission time Handle Problem Language Result Execution time Memory
757754 2023-06-13T17:41:38 Z taher Dreaming (IOI13_dreaming) C++17
59 / 100
1000 ms 11288 KB
#include <bits/stdc++.h>
#include "dreaming.h"

using namespace std;

const int maxN = (int) 1e5 + 1;
vector<vector<pair<int,int>>> adj;
int cnt = 0, n, m, l,sz = 0, ans = 0;
bool vis[maxN];
int parent[maxN];
vector<pair<int,int>> p;

void init(){
  adj.resize(n);
  p.resize(n);
  memset(parent, -1, sizeof(parent));
}

pair<int, int> bfs(int node){
  sz = 0;
  bool seen[n];
  int depth[n];
  memset(seen, 0, sizeof(seen));
  memset(depth, 0, sizeof(depth));
  int best_node = node, best_dist = 0;
  depth[node] = 0;
  seen[node] = true; vis[node] = true;
  queue<int> qs;
  qs.emplace(node);
  while(!qs.empty()){
    auto f = qs.front();
    sz++;
    if(depth[f] > best_dist){
      best_dist = depth[f];
      best_node = f;
    }
    qs.pop();
    for(auto x : adj[f]){
      if(seen[x.first]) continue;
      vis[x.first] = true;
      qs.emplace(x.first);
      parent[x.first] = f;
      depth[x.first] = x.second + depth[f];
      seen[x.first] = true;
    }
  }
  return make_pair(best_node, best_dist);
}

int Get_total(int node){
  auto val = bfs(node);
  auto f = bfs(val.first);
  return f.second;
}

void Do(int node){
  auto val = bfs(node);
  if(sz == 1) {
    p[cnt++] = make_pair(0, node);
    return ;
  }
  auto Tke = bfs(val.first);
  parent[val.first] = -1;
  int cur = Tke.first;
  vector<int> path, len;
  while(cur != -1){
    int nxt = parent[cur];
    path.emplace_back(cur);
    if(nxt == -1) break;
    auto q = lower_bound(adj[cur].begin(),adj[cur].end(), make_pair(nxt, 0));
    len.emplace_back((*q).second);
    cur = parent[cur];    
  }
  int Max = (int)1e9, best_node = -1, s = 0;
  for(int i = 0; i < (int)path.size(); i++){
    if(i > 0) s += len[i - 1];
    int now_max = max(s, Tke.second - s);
    if(now_max < Max){
      Max = now_max;
      best_node = path[i];
    }
  }
  ans = max(ans, Tke.second);
  assert(best_node != -1);
  p[cnt++] = make_pair(Max, best_node);
  return ;
}

void make(){
  for(int i = 0; i < n; i++){
    if(vis[i]) continue;
    Do(i);
    vis[i] = true;
  }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
  n = N;
  m = M;
  l = L;
  init();

  for (int i = 0; i < m; i++) {
    adj[A[i]].emplace_back(B[i], T[i]);
    adj[B[i]].emplace_back(A[i], T[i]);
  }

  for(int i = 0; i < n; i++){
    sort(adj[i].begin(),adj[i].end());
  }

  make();

  sort(p.rbegin(), p.rend());
  if(cnt >= 2) {
    ans = max(ans, p[0].first + p[1].first + l);
  }
  if(cnt >= 3) {
    ans = max(ans, p[1].first + p[2].first + 2 * l);
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 49 ms 10140 KB Output is correct
2 Correct 51 ms 10228 KB Output is correct
3 Correct 32 ms 6940 KB Output is correct
4 Correct 7 ms 2192 KB Output is correct
5 Correct 6 ms 1620 KB Output is correct
6 Correct 15 ms 2852 KB Output is correct
7 Correct 1 ms 692 KB Output is correct
8 Correct 30 ms 4704 KB Output is correct
9 Correct 29 ms 5836 KB Output is correct
10 Correct 1 ms 704 KB Output is correct
11 Correct 58 ms 7948 KB Output is correct
12 Correct 65 ms 9112 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 692 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 696 KB Output is correct
8 Correct 1 ms 696 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 696 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 724 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 704 KB Output is correct
23 Correct 1 ms 696 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 10140 KB Output is correct
2 Correct 51 ms 10228 KB Output is correct
3 Correct 32 ms 6940 KB Output is correct
4 Correct 7 ms 2192 KB Output is correct
5 Correct 6 ms 1620 KB Output is correct
6 Correct 15 ms 2852 KB Output is correct
7 Correct 1 ms 692 KB Output is correct
8 Correct 30 ms 4704 KB Output is correct
9 Correct 29 ms 5836 KB Output is correct
10 Correct 1 ms 704 KB Output is correct
11 Correct 58 ms 7948 KB Output is correct
12 Correct 65 ms 9112 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 692 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 696 KB Output is correct
21 Correct 1 ms 696 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 1 ms 696 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 724 KB Output is correct
34 Correct 1 ms 596 KB Output is correct
35 Correct 1 ms 704 KB Output is correct
36 Correct 1 ms 696 KB Output is correct
37 Correct 1 ms 596 KB Output is correct
38 Correct 1 ms 724 KB Output is correct
39 Correct 53 ms 10184 KB Output is correct
40 Correct 48 ms 10192 KB Output is correct
41 Correct 30 ms 6968 KB Output is correct
42 Correct 7 ms 2116 KB Output is correct
43 Correct 1 ms 724 KB Output is correct
44 Correct 1 ms 724 KB Output is correct
45 Correct 1 ms 724 KB Output is correct
46 Correct 1 ms 596 KB Output is correct
47 Correct 1 ms 696 KB Output is correct
48 Correct 1 ms 692 KB Output is correct
49 Correct 1 ms 696 KB Output is correct
50 Correct 1 ms 596 KB Output is correct
51 Correct 1 ms 596 KB Output is correct
52 Correct 1 ms 724 KB Output is correct
53 Correct 1 ms 724 KB Output is correct
54 Correct 1 ms 724 KB Output is correct
55 Correct 1 ms 596 KB Output is correct
56 Correct 1 ms 724 KB Output is correct
57 Correct 100 ms 10932 KB Output is correct
58 Correct 69 ms 10920 KB Output is correct
59 Correct 68 ms 10764 KB Output is correct
60 Correct 67 ms 10768 KB Output is correct
61 Correct 58 ms 10908 KB Output is correct
62 Correct 73 ms 10856 KB Output is correct
63 Correct 90 ms 10648 KB Output is correct
64 Correct 75 ms 10660 KB Output is correct
65 Correct 68 ms 10828 KB Output is correct
66 Correct 75 ms 10840 KB Output is correct
67 Correct 78 ms 10748 KB Output is correct
68 Correct 62 ms 10700 KB Output is correct
69 Correct 70 ms 11044 KB Output is correct
70 Correct 78 ms 11080 KB Output is correct
71 Correct 1 ms 596 KB Output is correct
72 Correct 2 ms 980 KB Output is correct
73 Correct 3 ms 888 KB Output is correct
74 Correct 2 ms 960 KB Output is correct
75 Correct 2 ms 956 KB Output is correct
76 Correct 2 ms 980 KB Output is correct
77 Correct 2 ms 980 KB Output is correct
78 Correct 2 ms 980 KB Output is correct
79 Correct 2 ms 1008 KB Output is correct
80 Correct 93 ms 10764 KB Output is correct
81 Correct 58 ms 10776 KB Output is correct
82 Correct 62 ms 10924 KB Output is correct
83 Correct 72 ms 10940 KB Output is correct
84 Correct 2 ms 852 KB Output is correct
85 Correct 2 ms 824 KB Output is correct
86 Correct 2 ms 836 KB Output is correct
87 Correct 3 ms 840 KB Output is correct
88 Correct 2 ms 852 KB Output is correct
89 Correct 2 ms 852 KB Output is correct
90 Correct 3 ms 852 KB Output is correct
91 Correct 2 ms 964 KB Output is correct
92 Correct 2 ms 968 KB Output is correct
93 Correct 3 ms 960 KB Output is correct
94 Correct 1 ms 696 KB Output is correct
95 Correct 1 ms 724 KB Output is correct
96 Correct 1 ms 700 KB Output is correct
97 Correct 1 ms 596 KB Output is correct
98 Correct 1 ms 724 KB Output is correct
99 Correct 1 ms 696 KB Output is correct
100 Correct 1 ms 596 KB Output is correct
101 Correct 1 ms 696 KB Output is correct
102 Correct 1 ms 696 KB Output is correct
103 Correct 1 ms 696 KB Output is correct
104 Correct 6 ms 1620 KB Output is correct
105 Correct 12 ms 2796 KB Output is correct
106 Correct 1 ms 696 KB Output is correct
107 Correct 30 ms 4744 KB Output is correct
108 Correct 30 ms 5872 KB Output is correct
109 Correct 1 ms 724 KB Output is correct
110 Correct 47 ms 7972 KB Output is correct
111 Correct 71 ms 9208 KB Output is correct
112 Correct 1 ms 704 KB Output is correct
113 Correct 83 ms 11288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1065 ms 6888 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 692 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 696 KB Output is correct
8 Correct 1 ms 696 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 696 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 724 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 704 KB Output is correct
23 Correct 1 ms 696 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 2 ms 852 KB Output is correct
28 Correct 3 ms 980 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 2 ms 852 KB Output is correct
31 Correct 2 ms 960 KB Output is correct
32 Correct 1 ms 704 KB Output is correct
33 Correct 3 ms 796 KB Output is correct
34 Correct 2 ms 980 KB Output is correct
35 Correct 1 ms 596 KB Output is correct
36 Correct 1 ms 696 KB Output is correct
37 Correct 1 ms 724 KB Output is correct
38 Correct 1 ms 596 KB Output is correct
39 Correct 1 ms 724 KB Output is correct
40 Correct 1 ms 596 KB Output is correct
41 Correct 1 ms 596 KB Output is correct
42 Correct 1 ms 696 KB Output is correct
43 Correct 1 ms 724 KB Output is correct
44 Correct 1 ms 724 KB Output is correct
45 Correct 1 ms 724 KB Output is correct
46 Correct 1 ms 596 KB Output is correct
47 Correct 1 ms 724 KB Output is correct
48 Correct 1 ms 596 KB Output is correct
49 Correct 1 ms 692 KB Output is correct
50 Correct 1 ms 696 KB Output is correct
51 Correct 1 ms 724 KB Output is correct
52 Correct 1 ms 596 KB Output is correct
53 Correct 1 ms 596 KB Output is correct
54 Correct 2 ms 980 KB Output is correct
55 Correct 2 ms 980 KB Output is correct
56 Correct 2 ms 852 KB Output is correct
57 Correct 2 ms 852 KB Output is correct
58 Correct 2 ms 980 KB Output is correct
59 Correct 2 ms 980 KB Output is correct
60 Correct 2 ms 852 KB Output is correct
61 Correct 3 ms 852 KB Output is correct
62 Correct 2 ms 980 KB Output is correct
63 Correct 2 ms 964 KB Output is correct
64 Correct 2 ms 820 KB Output is correct
65 Correct 3 ms 832 KB Output is correct
66 Correct 2 ms 964 KB Output is correct
67 Correct 2 ms 980 KB Output is correct
68 Correct 4 ms 864 KB Output is correct
69 Correct 3 ms 852 KB Output is correct
70 Correct 2 ms 852 KB Output is correct
71 Correct 3 ms 852 KB Output is correct
72 Correct 2 ms 1008 KB Output is correct
73 Correct 2 ms 980 KB Output is correct
74 Correct 2 ms 980 KB Output is correct
75 Correct 2 ms 980 KB Output is correct
76 Correct 2 ms 1012 KB Output is correct
77 Correct 2 ms 980 KB Output is correct
78 Correct 3 ms 852 KB Output is correct
79 Correct 3 ms 852 KB Output is correct
80 Correct 2 ms 724 KB Output is correct
81 Correct 2 ms 724 KB Output is correct
82 Correct 2 ms 980 KB Output is correct
83 Correct 2 ms 980 KB Output is correct
84 Correct 2 ms 852 KB Output is correct
85 Correct 2 ms 724 KB Output is correct
86 Correct 3 ms 896 KB Output is correct
87 Correct 2 ms 980 KB Output is correct
88 Correct 2 ms 852 KB Output is correct
89 Correct 3 ms 836 KB Output is correct
90 Correct 3 ms 852 KB Output is correct
91 Correct 2 ms 836 KB Output is correct
92 Correct 2 ms 840 KB Output is correct
93 Correct 2 ms 864 KB Output is correct
94 Correct 2 ms 852 KB Output is correct
95 Correct 2 ms 852 KB Output is correct
96 Correct 2 ms 852 KB Output is correct
97 Correct 2 ms 852 KB Output is correct
98 Correct 2 ms 964 KB Output is correct
99 Correct 2 ms 980 KB Output is correct
100 Correct 2 ms 980 KB Output is correct
101 Correct 2 ms 852 KB Output is correct
102 Correct 1 ms 724 KB Output is correct
103 Correct 1 ms 596 KB Output is correct
104 Correct 1 ms 724 KB Output is correct
105 Correct 1 ms 724 KB Output is correct
106 Correct 1 ms 696 KB Output is correct
107 Correct 1 ms 596 KB Output is correct
108 Correct 1 ms 724 KB Output is correct
109 Correct 1 ms 596 KB Output is correct
110 Correct 1 ms 724 KB Output is correct
111 Correct 1 ms 848 KB Output is correct
112 Correct 1 ms 724 KB Output is correct
113 Correct 1 ms 724 KB Output is correct
114 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 10140 KB Output is correct
2 Correct 51 ms 10228 KB Output is correct
3 Correct 32 ms 6940 KB Output is correct
4 Correct 7 ms 2192 KB Output is correct
5 Correct 6 ms 1620 KB Output is correct
6 Correct 15 ms 2852 KB Output is correct
7 Correct 1 ms 692 KB Output is correct
8 Correct 30 ms 4704 KB Output is correct
9 Correct 29 ms 5836 KB Output is correct
10 Correct 1 ms 704 KB Output is correct
11 Correct 58 ms 7948 KB Output is correct
12 Correct 65 ms 9112 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 692 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 696 KB Output is correct
21 Correct 1 ms 696 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 1 ms 696 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 724 KB Output is correct
34 Correct 1 ms 596 KB Output is correct
35 Correct 1 ms 704 KB Output is correct
36 Correct 1 ms 696 KB Output is correct
37 Correct 1 ms 596 KB Output is correct
38 Correct 1 ms 724 KB Output is correct
39 Correct 53 ms 10184 KB Output is correct
40 Correct 48 ms 10192 KB Output is correct
41 Correct 30 ms 6968 KB Output is correct
42 Correct 7 ms 2116 KB Output is correct
43 Correct 1 ms 724 KB Output is correct
44 Correct 1 ms 724 KB Output is correct
45 Correct 1 ms 724 KB Output is correct
46 Correct 1 ms 596 KB Output is correct
47 Correct 1 ms 696 KB Output is correct
48 Correct 1 ms 692 KB Output is correct
49 Correct 1 ms 696 KB Output is correct
50 Correct 1 ms 596 KB Output is correct
51 Correct 1 ms 596 KB Output is correct
52 Correct 1 ms 724 KB Output is correct
53 Correct 1 ms 724 KB Output is correct
54 Correct 1 ms 724 KB Output is correct
55 Correct 1 ms 596 KB Output is correct
56 Correct 1 ms 724 KB Output is correct
57 Correct 100 ms 10932 KB Output is correct
58 Correct 69 ms 10920 KB Output is correct
59 Correct 68 ms 10764 KB Output is correct
60 Correct 67 ms 10768 KB Output is correct
61 Correct 58 ms 10908 KB Output is correct
62 Correct 73 ms 10856 KB Output is correct
63 Correct 90 ms 10648 KB Output is correct
64 Correct 75 ms 10660 KB Output is correct
65 Correct 68 ms 10828 KB Output is correct
66 Correct 75 ms 10840 KB Output is correct
67 Correct 78 ms 10748 KB Output is correct
68 Correct 62 ms 10700 KB Output is correct
69 Correct 70 ms 11044 KB Output is correct
70 Correct 78 ms 11080 KB Output is correct
71 Correct 1 ms 596 KB Output is correct
72 Correct 2 ms 980 KB Output is correct
73 Correct 3 ms 888 KB Output is correct
74 Correct 2 ms 960 KB Output is correct
75 Correct 2 ms 956 KB Output is correct
76 Correct 2 ms 980 KB Output is correct
77 Correct 2 ms 980 KB Output is correct
78 Correct 2 ms 980 KB Output is correct
79 Correct 2 ms 1008 KB Output is correct
80 Correct 93 ms 10764 KB Output is correct
81 Correct 58 ms 10776 KB Output is correct
82 Correct 62 ms 10924 KB Output is correct
83 Correct 72 ms 10940 KB Output is correct
84 Correct 2 ms 852 KB Output is correct
85 Correct 2 ms 824 KB Output is correct
86 Correct 2 ms 836 KB Output is correct
87 Correct 3 ms 840 KB Output is correct
88 Correct 2 ms 852 KB Output is correct
89 Correct 2 ms 852 KB Output is correct
90 Correct 3 ms 852 KB Output is correct
91 Correct 2 ms 964 KB Output is correct
92 Correct 2 ms 968 KB Output is correct
93 Correct 3 ms 960 KB Output is correct
94 Correct 1 ms 696 KB Output is correct
95 Correct 1 ms 724 KB Output is correct
96 Correct 1 ms 700 KB Output is correct
97 Correct 1 ms 596 KB Output is correct
98 Correct 1 ms 724 KB Output is correct
99 Correct 1 ms 696 KB Output is correct
100 Correct 1 ms 596 KB Output is correct
101 Correct 1 ms 696 KB Output is correct
102 Correct 1 ms 696 KB Output is correct
103 Correct 1 ms 696 KB Output is correct
104 Correct 6 ms 1620 KB Output is correct
105 Correct 12 ms 2796 KB Output is correct
106 Correct 1 ms 696 KB Output is correct
107 Correct 30 ms 4744 KB Output is correct
108 Correct 30 ms 5872 KB Output is correct
109 Correct 1 ms 724 KB Output is correct
110 Correct 47 ms 7972 KB Output is correct
111 Correct 71 ms 9208 KB Output is correct
112 Correct 1 ms 704 KB Output is correct
113 Correct 83 ms 11288 KB Output is correct
114 Execution timed out 1065 ms 6888 KB Time limit exceeded
115 Halted 0 ms 0 KB -