Submission #388400

# Submission time Handle Problem Language Result Execution time Memory
388400 2021-04-11T10:33:16 Z cpp219 Dreaming (IOI13_dreaming) C++14
54 / 100
102 ms 16828 KB
#pragma GCC optimization "Ofast"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")
#include "dreaming.h"
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 1e5 + 6;
const ll lim = 3e5 + 6;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;
vector<ll> v;
vector<LL> g[N];
bool dd[N];
ll now = 1,L[N],R[N],d[N],pos[N],lens,par[N];

void DFS(ll u,ll p){
    dd[u] = 1; L[u] = R[u] = now; pos[now] = u; now++;
    for (auto i : g[u]){
        ll v = i.fs,L = i.sc;
        if (v != p) d[v] = d[u] + L,DFS(v,u),par[v] = u,R[u] = max(R[u],R[v]);
    }
}

ll farthest(ll root){
    now = 1; d[root] = 0; par[root] = -1; DFS(root,0); ll mx = -5,chosen;
    for (ll i = L[root];i <= R[root];i++){
        ll now = pos[i];
        if (mx < d[now]) chosen = now,mx = d[now];
        //cout<<now<<" "<<d[now]<<"\n";
    }
    return chosen;
}

ll Find_opt(ll now,ll total){
    ll mn = inf;
    while(now >= 0){
        ll low = total - d[now],high = d[now];
        //cout<<low<<" "<<high<<"\n";
        if (max(low,high) < mn) mn = min(mn,max(low,high));
        now = par[now];
    }
    //exit(0);
    return mn;
}

bool lf(ll x,ll y){
    return x > y;
}

int travelTime(int n, int m, int L, int A[], int B[], int T[]){
    ll ans = 0;
    for (ll i = 0;i < m;i++){
        g[A[i]].push_back({B[i],T[i]}); g[B[i]].push_back({A[i],T[i]});
    }
    for (ll i = 0;i < n;i++){
        if (!dd[i]){

            ll p = farthest(i); ll nxt = farthest(p);

            ans = max(ans,d[nxt]); v.push_back(Find_opt(nxt,d[nxt]));
        }
    }
    sort(v.begin(),v.end(),lf);
    //for (auto i : v) cout<<i<<" ";
    //exit(0);
    if (v.size() >= 2) ans = max(ans,v[0] + v[1] + L);
    if (v.size() > 2) ans = max(ans,v[1] + v[2] + 2*L);
    return ans;
}
/*
ll n,m,Len,A[N],B[N],T[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define task "test"
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>n>>m>>Len;
    for (ll i = 0;i < m;i++) cin>>A[i]>>B[i]>>T[i];
    cout<<travelTime(n,m,Len,A,B,T);
}
*/

Compilation message

dreaming.cpp:1: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    1 | #pragma GCC optimization "Ofast"
      | 
dreaming.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
dreaming.cpp: In function 'int farthest(int)':
dreaming.cpp:35:12: warning: 'chosen' may be used uninitialized in this function [-Wmaybe-uninitialized]
   35 |     return chosen;
      |            ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 62 ms 16724 KB Output is correct
2 Correct 53 ms 16720 KB Output is correct
3 Correct 35 ms 11984 KB Output is correct
4 Correct 8 ms 4684 KB Output is correct
5 Correct 7 ms 3788 KB Output is correct
6 Correct 16 ms 5708 KB Output is correct
7 Correct 2 ms 2648 KB Output is correct
8 Correct 30 ms 7508 KB Output is correct
9 Correct 39 ms 9544 KB Output is correct
10 Correct 2 ms 2764 KB Output is correct
11 Correct 62 ms 11872 KB Output is correct
12 Correct 59 ms 14148 KB Output is correct
13 Correct 2 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2656 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 2 ms 2648 KB Output is correct
13 Correct 3 ms 2636 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 2 ms 2720 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 2 ms 2636 KB Output is correct
23 Correct 3 ms 2636 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 2 ms 2656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 16724 KB Output is correct
2 Correct 53 ms 16720 KB Output is correct
3 Correct 35 ms 11984 KB Output is correct
4 Correct 8 ms 4684 KB Output is correct
5 Correct 7 ms 3788 KB Output is correct
6 Correct 16 ms 5708 KB Output is correct
7 Correct 2 ms 2648 KB Output is correct
8 Correct 30 ms 7508 KB Output is correct
9 Correct 39 ms 9544 KB Output is correct
10 Correct 2 ms 2764 KB Output is correct
11 Correct 62 ms 11872 KB Output is correct
12 Correct 59 ms 14148 KB Output is correct
13 Correct 2 ms 2764 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 2 ms 2656 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 2 ms 2636 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 2 ms 2648 KB Output is correct
26 Correct 3 ms 2636 KB Output is correct
27 Correct 2 ms 2636 KB Output is correct
28 Correct 2 ms 2636 KB Output is correct
29 Correct 2 ms 2636 KB Output is correct
30 Correct 2 ms 2636 KB Output is correct
31 Correct 2 ms 2720 KB Output is correct
32 Correct 2 ms 2652 KB Output is correct
33 Correct 2 ms 2636 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 2 ms 2636 KB Output is correct
36 Correct 3 ms 2636 KB Output is correct
37 Correct 2 ms 2636 KB Output is correct
38 Correct 2 ms 2656 KB Output is correct
39 Correct 54 ms 16828 KB Output is correct
40 Correct 61 ms 16708 KB Output is correct
41 Correct 42 ms 11984 KB Output is correct
42 Correct 9 ms 4684 KB Output is correct
43 Correct 2 ms 2636 KB Output is correct
44 Correct 2 ms 2636 KB Output is correct
45 Correct 2 ms 2636 KB Output is correct
46 Correct 2 ms 2636 KB Output is correct
47 Correct 2 ms 2636 KB Output is correct
48 Correct 2 ms 2636 KB Output is correct
49 Correct 2 ms 2636 KB Output is correct
50 Correct 2 ms 2652 KB Output is correct
51 Correct 2 ms 2636 KB Output is correct
52 Correct 2 ms 2636 KB Output is correct
53 Correct 2 ms 2652 KB Output is correct
54 Correct 2 ms 2636 KB Output is correct
55 Correct 2 ms 2648 KB Output is correct
56 Correct 2 ms 2636 KB Output is correct
57 Correct 76 ms 11260 KB Output is correct
58 Correct 77 ms 11032 KB Output is correct
59 Correct 102 ms 11100 KB Output is correct
60 Correct 76 ms 10976 KB Output is correct
61 Correct 70 ms 11096 KB Output is correct
62 Correct 67 ms 10980 KB Output is correct
63 Correct 77 ms 10872 KB Output is correct
64 Incorrect 61 ms 10984 KB Output isn't correct
65 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 7240 KB Output is correct
2 Correct 25 ms 7368 KB Output is correct
3 Correct 26 ms 7372 KB Output is correct
4 Correct 26 ms 7308 KB Output is correct
5 Correct 25 ms 7284 KB Output is correct
6 Correct 27 ms 7820 KB Output is correct
7 Correct 31 ms 7624 KB Output is correct
8 Correct 25 ms 7240 KB Output is correct
9 Correct 34 ms 7260 KB Output is correct
10 Correct 30 ms 7520 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 9 ms 4952 KB Output is correct
13 Correct 9 ms 4936 KB Output is correct
14 Correct 9 ms 4936 KB Output is correct
15 Correct 9 ms 4936 KB Output is correct
16 Correct 9 ms 4936 KB Output is correct
17 Correct 9 ms 4804 KB Output is correct
18 Correct 9 ms 5060 KB Output is correct
19 Correct 10 ms 4936 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 2 ms 2764 KB Output is correct
23 Correct 9 ms 4936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2656 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 2 ms 2648 KB Output is correct
13 Correct 3 ms 2636 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 2 ms 2720 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 2 ms 2636 KB Output is correct
23 Correct 3 ms 2636 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 2 ms 2656 KB Output is correct
26 Correct 2 ms 2764 KB Output is correct
27 Correct 3 ms 2764 KB Output is correct
28 Correct 3 ms 2892 KB Output is correct
29 Correct 3 ms 2636 KB Output is correct
30 Correct 4 ms 2764 KB Output is correct
31 Correct 3 ms 2892 KB Output is correct
32 Correct 2 ms 2764 KB Output is correct
33 Correct 3 ms 2764 KB Output is correct
34 Correct 3 ms 2892 KB Output is correct
35 Correct 2 ms 2636 KB Output is correct
36 Correct 2 ms 2636 KB Output is correct
37 Correct 2 ms 2636 KB Output is correct
38 Correct 2 ms 2636 KB Output is correct
39 Correct 2 ms 2636 KB Output is correct
40 Correct 2 ms 2652 KB Output is correct
41 Correct 2 ms 2636 KB Output is correct
42 Correct 2 ms 2636 KB Output is correct
43 Correct 2 ms 2636 KB Output is correct
44 Correct 2 ms 2636 KB Output is correct
45 Correct 3 ms 2648 KB Output is correct
46 Correct 2 ms 2652 KB Output is correct
47 Correct 2 ms 2636 KB Output is correct
48 Correct 2 ms 2648 KB Output is correct
49 Correct 2 ms 2656 KB Output is correct
50 Correct 2 ms 2636 KB Output is correct
51 Correct 2 ms 2656 KB Output is correct
52 Correct 2 ms 2640 KB Output is correct
53 Correct 2 ms 2636 KB Output is correct
54 Correct 4 ms 3020 KB Output is correct
55 Correct 4 ms 3020 KB Output is correct
56 Correct 3 ms 2792 KB Output is correct
57 Correct 2 ms 2764 KB Output is correct
58 Correct 3 ms 2892 KB Output is correct
59 Correct 3 ms 2892 KB Output is correct
60 Correct 3 ms 2764 KB Output is correct
61 Correct 3 ms 2764 KB Output is correct
62 Correct 3 ms 2892 KB Output is correct
63 Correct 3 ms 2892 KB Output is correct
64 Correct 2 ms 2764 KB Output is correct
65 Correct 3 ms 2764 KB Output is correct
66 Correct 3 ms 2892 KB Output is correct
67 Correct 3 ms 2892 KB Output is correct
68 Correct 3 ms 2788 KB Output is correct
69 Correct 3 ms 2764 KB Output is correct
70 Correct 3 ms 2764 KB Output is correct
71 Correct 3 ms 2764 KB Output is correct
72 Correct 3 ms 2892 KB Output is correct
73 Correct 3 ms 2892 KB Output is correct
74 Correct 3 ms 2892 KB Output is correct
75 Correct 3 ms 2892 KB Output is correct
76 Correct 3 ms 2892 KB Output is correct
77 Correct 3 ms 2892 KB Output is correct
78 Correct 3 ms 2764 KB Output is correct
79 Correct 3 ms 2764 KB Output is correct
80 Correct 2 ms 2764 KB Output is correct
81 Correct 2 ms 2764 KB Output is correct
82 Correct 3 ms 2892 KB Output is correct
83 Correct 3 ms 2916 KB Output is correct
84 Correct 3 ms 2764 KB Output is correct
85 Correct 2 ms 2764 KB Output is correct
86 Correct 4 ms 2764 KB Output is correct
87 Correct 3 ms 2892 KB Output is correct
88 Correct 3 ms 2764 KB Output is correct
89 Correct 3 ms 2764 KB Output is correct
90 Correct 3 ms 2764 KB Output is correct
91 Correct 3 ms 2796 KB Output is correct
92 Correct 3 ms 2792 KB Output is correct
93 Correct 3 ms 2764 KB Output is correct
94 Correct 3 ms 2892 KB Output is correct
95 Correct 4 ms 2788 KB Output is correct
96 Correct 4 ms 2820 KB Output is correct
97 Correct 3 ms 2796 KB Output is correct
98 Correct 3 ms 2892 KB Output is correct
99 Correct 3 ms 2892 KB Output is correct
100 Correct 3 ms 2892 KB Output is correct
101 Correct 3 ms 2892 KB Output is correct
102 Correct 2 ms 2652 KB Output is correct
103 Correct 2 ms 2636 KB Output is correct
104 Correct 2 ms 2636 KB Output is correct
105 Correct 2 ms 2636 KB Output is correct
106 Correct 2 ms 2636 KB Output is correct
107 Correct 2 ms 2636 KB Output is correct
108 Correct 2 ms 2636 KB Output is correct
109 Correct 2 ms 2636 KB Output is correct
110 Correct 2 ms 2636 KB Output is correct
111 Correct 2 ms 2652 KB Output is correct
112 Correct 2 ms 2636 KB Output is correct
113 Correct 2 ms 2652 KB Output is correct
114 Correct 2 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 16724 KB Output is correct
2 Correct 53 ms 16720 KB Output is correct
3 Correct 35 ms 11984 KB Output is correct
4 Correct 8 ms 4684 KB Output is correct
5 Correct 7 ms 3788 KB Output is correct
6 Correct 16 ms 5708 KB Output is correct
7 Correct 2 ms 2648 KB Output is correct
8 Correct 30 ms 7508 KB Output is correct
9 Correct 39 ms 9544 KB Output is correct
10 Correct 2 ms 2764 KB Output is correct
11 Correct 62 ms 11872 KB Output is correct
12 Correct 59 ms 14148 KB Output is correct
13 Correct 2 ms 2764 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 2 ms 2656 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 2 ms 2636 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 2 ms 2648 KB Output is correct
26 Correct 3 ms 2636 KB Output is correct
27 Correct 2 ms 2636 KB Output is correct
28 Correct 2 ms 2636 KB Output is correct
29 Correct 2 ms 2636 KB Output is correct
30 Correct 2 ms 2636 KB Output is correct
31 Correct 2 ms 2720 KB Output is correct
32 Correct 2 ms 2652 KB Output is correct
33 Correct 2 ms 2636 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 2 ms 2636 KB Output is correct
36 Correct 3 ms 2636 KB Output is correct
37 Correct 2 ms 2636 KB Output is correct
38 Correct 2 ms 2656 KB Output is correct
39 Correct 54 ms 16828 KB Output is correct
40 Correct 61 ms 16708 KB Output is correct
41 Correct 42 ms 11984 KB Output is correct
42 Correct 9 ms 4684 KB Output is correct
43 Correct 2 ms 2636 KB Output is correct
44 Correct 2 ms 2636 KB Output is correct
45 Correct 2 ms 2636 KB Output is correct
46 Correct 2 ms 2636 KB Output is correct
47 Correct 2 ms 2636 KB Output is correct
48 Correct 2 ms 2636 KB Output is correct
49 Correct 2 ms 2636 KB Output is correct
50 Correct 2 ms 2652 KB Output is correct
51 Correct 2 ms 2636 KB Output is correct
52 Correct 2 ms 2636 KB Output is correct
53 Correct 2 ms 2652 KB Output is correct
54 Correct 2 ms 2636 KB Output is correct
55 Correct 2 ms 2648 KB Output is correct
56 Correct 2 ms 2636 KB Output is correct
57 Correct 76 ms 11260 KB Output is correct
58 Correct 77 ms 11032 KB Output is correct
59 Correct 102 ms 11100 KB Output is correct
60 Correct 76 ms 10976 KB Output is correct
61 Correct 70 ms 11096 KB Output is correct
62 Correct 67 ms 10980 KB Output is correct
63 Correct 77 ms 10872 KB Output is correct
64 Incorrect 61 ms 10984 KB Output isn't correct
65 Halted 0 ms 0 KB -