답안 #661294

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
661294 2022-11-25T11:31:29 Z atigun 꿈 (IOI13_dreaming) C++11
47 / 100
120 ms 36956 KB
#include<bits/stdc++.h>
#include"dreaming.h"

using namespace std;
typedef long long ll;

const int maxn = 1e5;
vector<vector<pair<int, int>>> g(maxn+5);
vector<bool> vis(maxn+5, false);
vector<int> dt(maxn+5), ht(maxn+5, 0), group(maxn+5);
vector<multiset<int>> S(maxn+5);

void dfs1(int v, int P){
  group[v] = P;
  vis[v] = 1;
  int maxi1 = 0, maxi2 = 0;
  for(pair<int, int> pp : g[v]){
    int u = pp.first, w = pp.second;
    if(vis[u])
      continue;
    dfs1(u, P);
    ht[v] = max(ht[v], ht[u]+w);
    if(ht[u]+w >= maxi1){
      maxi2 = maxi1, maxi1 = ht[u]+w;
    } else if(ht[u]+w >= maxi2){
      maxi2 = ht[u]+w;
    }
  }
  dt[v] = maxi1+maxi2;
}

void dfs2(int v, int p){
  vis[v] = 1;
  for(pair<int, int> pp : g[v]){
    int u = pp.first, w = pp.second;
    if(u == p)
      continue;
    S[v].insert(ht[u]+w);
  }
  for(pair<int, int> pp : g[v]){
    int u = pp.first, w = pp.second;
    if(u == p)
      continue;
    if(S[v].size() == 1){
      S[u].insert(w);
    } else if(!S[v].empty()){
      S[v].erase(S[v].find(ht[u]+w));
      int best = *--S[v].end();
      S[u].insert(best+w);
      S[v].insert(ht[u]+w);
    }
  }
  if(!S[v].empty())
    ht[v] = *--S[v].end();
  for(pair<int, int> pp : g[v]){
    int u = pp.first;
    if(vis[u])
      continue;
    dfs2(u, v);
  }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]){
  for(int i = 0; i < M; i++){
    g[A[i]].emplace_back(B[i], T[i]);
    g[B[i]].emplace_back(A[i], T[i]);
  }
  for(int i = 0; i < N; i++)
    if(!vis[i])
      dfs1(i, i);
  fill(vis.begin(), vis.end(), false);
  for(int i = 0; i < N; i++)
    if(!vis[i])
      dfs2(i, -1);
  int ans = 0;
  for(int i = 0; i < N; i++)
    ans = max(ans, dt[i]);  
  vector<pair<int, int>> order;
  order.reserve(N);
  for(int i = 0; i < N; i++)
    order.emplace_back(ht[i], group[i]);
  sort(order.begin(), order.end());
  vector<int> G;
  G.reserve(N);
  vector<bool> used(N+5, false);
  for(int i = 0; i < N; i++){
    if(used[order[i].second])
      continue;
    G.emplace_back(order[i].first);
    used[order[i].second] = true;
  }
  int GN = G.size();
  sort(G.begin(), G.end(), [&](int n1, int n2){
    return n1 > n2;
  });
  for(int i = GN-1; i > 0; i--)
    ans = max(ans, G[0] + G[i] + i*L);
  return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 29260 KB Output is correct
2 Correct 85 ms 28828 KB Output is correct
3 Correct 54 ms 24564 KB Output is correct
4 Correct 13 ms 11504 KB Output is correct
5 Correct 11 ms 10452 KB Output is correct
6 Correct 19 ms 13148 KB Output is correct
7 Correct 5 ms 8532 KB Output is correct
8 Correct 35 ms 17224 KB Output is correct
9 Correct 47 ms 21312 KB Output is correct
10 Correct 5 ms 8684 KB Output is correct
11 Correct 81 ms 23984 KB Output is correct
12 Correct 85 ms 26380 KB Output is correct
13 Correct 5 ms 8692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8560 KB Output is correct
2 Correct 4 ms 8532 KB Output is correct
3 Correct 5 ms 8532 KB Output is correct
4 Correct 4 ms 8452 KB Output is correct
5 Correct 4 ms 8532 KB Output is correct
6 Correct 4 ms 8532 KB Output is correct
7 Correct 4 ms 8556 KB Output is correct
8 Correct 4 ms 8576 KB Output is correct
9 Correct 4 ms 8532 KB Output is correct
10 Correct 4 ms 8532 KB Output is correct
11 Correct 4 ms 8556 KB Output is correct
12 Correct 4 ms 8532 KB Output is correct
13 Correct 4 ms 8660 KB Output is correct
14 Correct 5 ms 8532 KB Output is correct
15 Correct 4 ms 8532 KB Output is correct
16 Correct 5 ms 8476 KB Output is correct
17 Correct 4 ms 8532 KB Output is correct
18 Correct 4 ms 8532 KB Output is correct
19 Correct 4 ms 8532 KB Output is correct
20 Correct 5 ms 8532 KB Output is correct
21 Correct 4 ms 8532 KB Output is correct
22 Correct 5 ms 8552 KB Output is correct
23 Correct 5 ms 8532 KB Output is correct
24 Correct 5 ms 8532 KB Output is correct
25 Correct 4 ms 8552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 29260 KB Output is correct
2 Correct 85 ms 28828 KB Output is correct
3 Correct 54 ms 24564 KB Output is correct
4 Correct 13 ms 11504 KB Output is correct
5 Correct 11 ms 10452 KB Output is correct
6 Correct 19 ms 13148 KB Output is correct
7 Correct 5 ms 8532 KB Output is correct
8 Correct 35 ms 17224 KB Output is correct
9 Correct 47 ms 21312 KB Output is correct
10 Correct 5 ms 8684 KB Output is correct
11 Correct 81 ms 23984 KB Output is correct
12 Correct 85 ms 26380 KB Output is correct
13 Correct 5 ms 8692 KB Output is correct
14 Correct 4 ms 8560 KB Output is correct
15 Correct 4 ms 8532 KB Output is correct
16 Correct 5 ms 8532 KB Output is correct
17 Correct 4 ms 8452 KB Output is correct
18 Correct 4 ms 8532 KB Output is correct
19 Correct 4 ms 8532 KB Output is correct
20 Correct 4 ms 8556 KB Output is correct
21 Correct 4 ms 8576 KB Output is correct
22 Correct 4 ms 8532 KB Output is correct
23 Correct 4 ms 8532 KB Output is correct
24 Correct 4 ms 8556 KB Output is correct
25 Correct 4 ms 8532 KB Output is correct
26 Correct 4 ms 8660 KB Output is correct
27 Correct 5 ms 8532 KB Output is correct
28 Correct 4 ms 8532 KB Output is correct
29 Correct 5 ms 8476 KB Output is correct
30 Correct 4 ms 8532 KB Output is correct
31 Correct 4 ms 8532 KB Output is correct
32 Correct 4 ms 8532 KB Output is correct
33 Correct 5 ms 8532 KB Output is correct
34 Correct 4 ms 8532 KB Output is correct
35 Correct 5 ms 8552 KB Output is correct
36 Correct 5 ms 8532 KB Output is correct
37 Correct 5 ms 8532 KB Output is correct
38 Correct 4 ms 8552 KB Output is correct
39 Correct 86 ms 29292 KB Output is correct
40 Correct 94 ms 28912 KB Output is correct
41 Correct 52 ms 24560 KB Output is correct
42 Correct 14 ms 11564 KB Output is correct
43 Correct 4 ms 8532 KB Output is correct
44 Correct 5 ms 8560 KB Output is correct
45 Correct 4 ms 8552 KB Output is correct
46 Correct 5 ms 8552 KB Output is correct
47 Correct 5 ms 8532 KB Output is correct
48 Correct 5 ms 8532 KB Output is correct
49 Correct 5 ms 8532 KB Output is correct
50 Correct 4 ms 8532 KB Output is correct
51 Correct 5 ms 8532 KB Output is correct
52 Correct 4 ms 8560 KB Output is correct
53 Correct 5 ms 8532 KB Output is correct
54 Correct 4 ms 8560 KB Output is correct
55 Correct 5 ms 8660 KB Output is correct
56 Correct 5 ms 8560 KB Output is correct
57 Correct 103 ms 25124 KB Output is correct
58 Correct 108 ms 25156 KB Output is correct
59 Correct 103 ms 25136 KB Output is correct
60 Correct 107 ms 25080 KB Output is correct
61 Correct 111 ms 25164 KB Output is correct
62 Correct 104 ms 25212 KB Output is correct
63 Correct 98 ms 24816 KB Output is correct
64 Correct 98 ms 24888 KB Output is correct
65 Correct 113 ms 25160 KB Output is correct
66 Correct 112 ms 25108 KB Output is correct
67 Correct 110 ms 25240 KB Output is correct
68 Correct 104 ms 25200 KB Output is correct
69 Correct 108 ms 25496 KB Output is correct
70 Correct 120 ms 25420 KB Output is correct
71 Correct 4 ms 8532 KB Output is correct
72 Correct 6 ms 9044 KB Output is correct
73 Correct 6 ms 9044 KB Output is correct
74 Correct 6 ms 8952 KB Output is correct
75 Correct 6 ms 8952 KB Output is correct
76 Correct 6 ms 9044 KB Output is correct
77 Correct 6 ms 9044 KB Output is correct
78 Correct 6 ms 9044 KB Output is correct
79 Correct 7 ms 8948 KB Output is correct
80 Correct 105 ms 25144 KB Output is correct
81 Correct 102 ms 25168 KB Output is correct
82 Correct 106 ms 25172 KB Output is correct
83 Correct 110 ms 25328 KB Output is correct
84 Correct 7 ms 8916 KB Output is correct
85 Correct 5 ms 8916 KB Output is correct
86 Correct 6 ms 8916 KB Output is correct
87 Correct 6 ms 8916 KB Output is correct
88 Correct 7 ms 8884 KB Output is correct
89 Correct 6 ms 9044 KB Output is correct
90 Correct 6 ms 8952 KB Output is correct
91 Correct 7 ms 9044 KB Output is correct
92 Correct 6 ms 8956 KB Output is correct
93 Correct 6 ms 8916 KB Output is correct
94 Correct 4 ms 8532 KB Output is correct
95 Correct 5 ms 8556 KB Output is correct
96 Correct 5 ms 8532 KB Output is correct
97 Correct 4 ms 8532 KB Output is correct
98 Correct 5 ms 8532 KB Output is correct
99 Correct 5 ms 8484 KB Output is correct
100 Correct 5 ms 8532 KB Output is correct
101 Correct 4 ms 8552 KB Output is correct
102 Correct 4 ms 8532 KB Output is correct
103 Correct 4 ms 8556 KB Output is correct
104 Correct 11 ms 10452 KB Output is correct
105 Correct 20 ms 13032 KB Output is correct
106 Correct 5 ms 8532 KB Output is correct
107 Correct 36 ms 17336 KB Output is correct
108 Correct 49 ms 21256 KB Output is correct
109 Correct 4 ms 8660 KB Output is correct
110 Correct 71 ms 23872 KB Output is correct
111 Correct 89 ms 26356 KB Output is correct
112 Correct 5 ms 8688 KB Output is correct
113 Correct 108 ms 36956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 39 ms 15160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8560 KB Output is correct
2 Correct 4 ms 8532 KB Output is correct
3 Correct 5 ms 8532 KB Output is correct
4 Correct 4 ms 8452 KB Output is correct
5 Correct 4 ms 8532 KB Output is correct
6 Correct 4 ms 8532 KB Output is correct
7 Correct 4 ms 8556 KB Output is correct
8 Correct 4 ms 8576 KB Output is correct
9 Correct 4 ms 8532 KB Output is correct
10 Correct 4 ms 8532 KB Output is correct
11 Correct 4 ms 8556 KB Output is correct
12 Correct 4 ms 8532 KB Output is correct
13 Correct 4 ms 8660 KB Output is correct
14 Correct 5 ms 8532 KB Output is correct
15 Correct 4 ms 8532 KB Output is correct
16 Correct 5 ms 8476 KB Output is correct
17 Correct 4 ms 8532 KB Output is correct
18 Correct 4 ms 8532 KB Output is correct
19 Correct 4 ms 8532 KB Output is correct
20 Correct 5 ms 8532 KB Output is correct
21 Correct 4 ms 8532 KB Output is correct
22 Correct 5 ms 8552 KB Output is correct
23 Correct 5 ms 8532 KB Output is correct
24 Correct 5 ms 8532 KB Output is correct
25 Correct 4 ms 8552 KB Output is correct
26 Incorrect 5 ms 8660 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 29260 KB Output is correct
2 Correct 85 ms 28828 KB Output is correct
3 Correct 54 ms 24564 KB Output is correct
4 Correct 13 ms 11504 KB Output is correct
5 Correct 11 ms 10452 KB Output is correct
6 Correct 19 ms 13148 KB Output is correct
7 Correct 5 ms 8532 KB Output is correct
8 Correct 35 ms 17224 KB Output is correct
9 Correct 47 ms 21312 KB Output is correct
10 Correct 5 ms 8684 KB Output is correct
11 Correct 81 ms 23984 KB Output is correct
12 Correct 85 ms 26380 KB Output is correct
13 Correct 5 ms 8692 KB Output is correct
14 Correct 4 ms 8560 KB Output is correct
15 Correct 4 ms 8532 KB Output is correct
16 Correct 5 ms 8532 KB Output is correct
17 Correct 4 ms 8452 KB Output is correct
18 Correct 4 ms 8532 KB Output is correct
19 Correct 4 ms 8532 KB Output is correct
20 Correct 4 ms 8556 KB Output is correct
21 Correct 4 ms 8576 KB Output is correct
22 Correct 4 ms 8532 KB Output is correct
23 Correct 4 ms 8532 KB Output is correct
24 Correct 4 ms 8556 KB Output is correct
25 Correct 4 ms 8532 KB Output is correct
26 Correct 4 ms 8660 KB Output is correct
27 Correct 5 ms 8532 KB Output is correct
28 Correct 4 ms 8532 KB Output is correct
29 Correct 5 ms 8476 KB Output is correct
30 Correct 4 ms 8532 KB Output is correct
31 Correct 4 ms 8532 KB Output is correct
32 Correct 4 ms 8532 KB Output is correct
33 Correct 5 ms 8532 KB Output is correct
34 Correct 4 ms 8532 KB Output is correct
35 Correct 5 ms 8552 KB Output is correct
36 Correct 5 ms 8532 KB Output is correct
37 Correct 5 ms 8532 KB Output is correct
38 Correct 4 ms 8552 KB Output is correct
39 Correct 86 ms 29292 KB Output is correct
40 Correct 94 ms 28912 KB Output is correct
41 Correct 52 ms 24560 KB Output is correct
42 Correct 14 ms 11564 KB Output is correct
43 Correct 4 ms 8532 KB Output is correct
44 Correct 5 ms 8560 KB Output is correct
45 Correct 4 ms 8552 KB Output is correct
46 Correct 5 ms 8552 KB Output is correct
47 Correct 5 ms 8532 KB Output is correct
48 Correct 5 ms 8532 KB Output is correct
49 Correct 5 ms 8532 KB Output is correct
50 Correct 4 ms 8532 KB Output is correct
51 Correct 5 ms 8532 KB Output is correct
52 Correct 4 ms 8560 KB Output is correct
53 Correct 5 ms 8532 KB Output is correct
54 Correct 4 ms 8560 KB Output is correct
55 Correct 5 ms 8660 KB Output is correct
56 Correct 5 ms 8560 KB Output is correct
57 Correct 103 ms 25124 KB Output is correct
58 Correct 108 ms 25156 KB Output is correct
59 Correct 103 ms 25136 KB Output is correct
60 Correct 107 ms 25080 KB Output is correct
61 Correct 111 ms 25164 KB Output is correct
62 Correct 104 ms 25212 KB Output is correct
63 Correct 98 ms 24816 KB Output is correct
64 Correct 98 ms 24888 KB Output is correct
65 Correct 113 ms 25160 KB Output is correct
66 Correct 112 ms 25108 KB Output is correct
67 Correct 110 ms 25240 KB Output is correct
68 Correct 104 ms 25200 KB Output is correct
69 Correct 108 ms 25496 KB Output is correct
70 Correct 120 ms 25420 KB Output is correct
71 Correct 4 ms 8532 KB Output is correct
72 Correct 6 ms 9044 KB Output is correct
73 Correct 6 ms 9044 KB Output is correct
74 Correct 6 ms 8952 KB Output is correct
75 Correct 6 ms 8952 KB Output is correct
76 Correct 6 ms 9044 KB Output is correct
77 Correct 6 ms 9044 KB Output is correct
78 Correct 6 ms 9044 KB Output is correct
79 Correct 7 ms 8948 KB Output is correct
80 Correct 105 ms 25144 KB Output is correct
81 Correct 102 ms 25168 KB Output is correct
82 Correct 106 ms 25172 KB Output is correct
83 Correct 110 ms 25328 KB Output is correct
84 Correct 7 ms 8916 KB Output is correct
85 Correct 5 ms 8916 KB Output is correct
86 Correct 6 ms 8916 KB Output is correct
87 Correct 6 ms 8916 KB Output is correct
88 Correct 7 ms 8884 KB Output is correct
89 Correct 6 ms 9044 KB Output is correct
90 Correct 6 ms 8952 KB Output is correct
91 Correct 7 ms 9044 KB Output is correct
92 Correct 6 ms 8956 KB Output is correct
93 Correct 6 ms 8916 KB Output is correct
94 Correct 4 ms 8532 KB Output is correct
95 Correct 5 ms 8556 KB Output is correct
96 Correct 5 ms 8532 KB Output is correct
97 Correct 4 ms 8532 KB Output is correct
98 Correct 5 ms 8532 KB Output is correct
99 Correct 5 ms 8484 KB Output is correct
100 Correct 5 ms 8532 KB Output is correct
101 Correct 4 ms 8552 KB Output is correct
102 Correct 4 ms 8532 KB Output is correct
103 Correct 4 ms 8556 KB Output is correct
104 Correct 11 ms 10452 KB Output is correct
105 Correct 20 ms 13032 KB Output is correct
106 Correct 5 ms 8532 KB Output is correct
107 Correct 36 ms 17336 KB Output is correct
108 Correct 49 ms 21256 KB Output is correct
109 Correct 4 ms 8660 KB Output is correct
110 Correct 71 ms 23872 KB Output is correct
111 Correct 89 ms 26356 KB Output is correct
112 Correct 5 ms 8688 KB Output is correct
113 Correct 108 ms 36956 KB Output is correct
114 Incorrect 39 ms 15160 KB Output isn't correct
115 Halted 0 ms 0 KB -