Submission #561469

# Submission time Handle Problem Language Result Execution time Memory
561469 2022-05-12T22:14:10 Z urosk Dreaming (IOI13_dreaming) C++14
47 / 100
108 ms 16716 KB
#include "dreaming.h"
#define here cerr<<"===========================================\n"
#include <bits/stdc++.h>
#define ld double
#define ll int
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
using namespace std;
#define maxn 100005
ll n,m,l;
vector<pll> g[maxn];
ll dp[maxn];
ll up[maxn];
pll dpmx[maxn];
bool vis[maxn];
ll dsu[maxn];
ll root(ll x){
    while(x!=dsu[x]){
        dsu[x] = dsu[dsu[x]];
        x = dsu[x];
    }
    return x;
}
void upd(ll x,ll y){
    x = root(x);
    y = root(y);
    if(dp[x]>dp[y]) dsu[x] = y;
    else dsu[y] = x;
}
void dfs(ll u,ll par){
    vis[u] = 1;
    dp[u] = 0;
    dpmx[u] = {0,0};
    for(pll p : g[u]){
        ll s = p.fi;
        ll w = p.sc;
        if(s==par) continue;
        dfs(s,u);
        dp[u] = max(dp[s]+w,dp[u]);
        if(dp[s]+w>dpmx[u].fi){
            dpmx[u].sc = dpmx[u].fi;
            dpmx[u].fi = dp[s]+w;
        }else if(dp[s]+w>dpmx[u].sc){
            dpmx[u].sc = dp[s]+w;
        }
    }
}
void dfs2(ll u,ll par,ll w){
    if(u!=par){
        up[u] = up[par]+w;
        pll p = dpmx[par];
        ll x;
        if(dp[u]+w==p.fi) x = p.sc;
        else x = p.fi;
        up[u] = max(up[u],x+w);
    }
    vis[u] = 1;
    for(pll p : g[u]){
        ll s = p.fi;
        ll w = p.sc;
        if(s==par) continue;
        dfs2(s,u,w);
    }
}
void dfs3(ll u,ll par){
    vis[u] = 1;
    for(pll p : g[u]){
        ll s = p.fi;
        ll w = p.sc;
        if(s==par) continue;
        upd(s,u);
        dfs3(s,u);
    }
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    n = N; m = M; l = L;
    iota(dsu+1,dsu+n+1,1);
    for(ll i = 0;i<m;i++){
        ll x = A[i];
        ll y = B[i];
        ll w = T[i];
        x++;
        y++;
        g[x].pb({y,w});
        g[y].pb({x,w});
    }
    for(ll i = 1;i<=n;i++) if(!vis[i]) dfs(i,i);
    fill(vis,vis+n+1,0);
    for(ll i = 1;i<=n;i++) if(!vis[i]) dfs2(i,i,0);
    for(ll i = 1;i<=n;i++) dp[i] = max(dp[i],up[i]);
    fill(vis,vis+n+1,0);
    for(ll i = 1;i<=n;i++) if(!vis[i]) dfs3(i,i);
    ll ans = 0;
    for(ll i = 1;i<=n;i++) ans = max(ans,dp[i]);
    fill(vis,vis+n+1,0);
    priority_queue<ll> pq;
    for(ll i = 1;i<=n;i++){
        ll x = root(i);
        if(vis[x]) continue;
        pq.push(-dp[x]);
        vis[x] = 1;
    }
    while(sz(pq)>=2){
        ll x = -pq.top();
        pq.pop();
        ll y = -pq.top();
        pq.pop();
        ll z = min(max(x+l,y),max(y+l,x));
        ans = max(ans,x+y+l);
        pq.push(-z);
    }
    if(sz(pq)) ans = max(ans,-pq.top());
    return ans;
}

Compilation message

dreaming.cpp: In function 'void dfs3(int, int)':
dreaming.cpp:81:12: warning: unused variable 'w' [-Wunused-variable]
   81 |         ll w = p.sc;
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 44 ms 12324 KB Output is correct
2 Correct 48 ms 12104 KB Output is correct
3 Correct 46 ms 10472 KB Output is correct
4 Correct 8 ms 4064 KB Output is correct
5 Correct 8 ms 3412 KB Output is correct
6 Correct 13 ms 4808 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 22 ms 6852 KB Output is correct
9 Correct 28 ms 9016 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 41 ms 9836 KB Output is correct
12 Correct 54 ms 11116 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 3 ms 2652 KB Output is correct
6 Correct 3 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2656 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2660 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 2 ms 2648 KB Output is correct
17 Correct 2 ms 2656 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 3 ms 2644 KB Output is correct
21 Correct 3 ms 2644 KB Output is correct
22 Correct 3 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 3 ms 2644 KB Output is correct
25 Correct 2 ms 2660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 12324 KB Output is correct
2 Correct 48 ms 12104 KB Output is correct
3 Correct 46 ms 10472 KB Output is correct
4 Correct 8 ms 4064 KB Output is correct
5 Correct 8 ms 3412 KB Output is correct
6 Correct 13 ms 4808 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 22 ms 6852 KB Output is correct
9 Correct 28 ms 9016 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 41 ms 9836 KB Output is correct
12 Correct 54 ms 11116 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 3 ms 2644 KB Output is correct
18 Correct 3 ms 2652 KB Output is correct
19 Correct 3 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2656 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2660 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 2 ms 2648 KB Output is correct
30 Correct 2 ms 2656 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 2 ms 2644 KB Output is correct
33 Correct 3 ms 2644 KB Output is correct
34 Correct 3 ms 2644 KB Output is correct
35 Correct 3 ms 2644 KB Output is correct
36 Correct 2 ms 2644 KB Output is correct
37 Correct 3 ms 2644 KB Output is correct
38 Correct 2 ms 2660 KB Output is correct
39 Correct 49 ms 12512 KB Output is correct
40 Correct 44 ms 12216 KB Output is correct
41 Correct 32 ms 10600 KB Output is correct
42 Correct 8 ms 4220 KB Output is correct
43 Correct 2 ms 2644 KB Output is correct
44 Correct 2 ms 2644 KB Output is correct
45 Correct 2 ms 2652 KB Output is correct
46 Correct 2 ms 2644 KB Output is correct
47 Correct 2 ms 2644 KB Output is correct
48 Correct 2 ms 2652 KB Output is correct
49 Correct 3 ms 2644 KB Output is correct
50 Correct 2 ms 2644 KB Output is correct
51 Correct 3 ms 2644 KB Output is correct
52 Correct 2 ms 2656 KB Output is correct
53 Correct 2 ms 2644 KB Output is correct
54 Correct 2 ms 2644 KB Output is correct
55 Correct 2 ms 2644 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 65 ms 9864 KB Output is correct
58 Correct 69 ms 9872 KB Output is correct
59 Correct 108 ms 9808 KB Output is correct
60 Correct 88 ms 9896 KB Output is correct
61 Correct 75 ms 9820 KB Output is correct
62 Correct 62 ms 9832 KB Output is correct
63 Correct 84 ms 9656 KB Output is correct
64 Correct 68 ms 9660 KB Output is correct
65 Correct 64 ms 9668 KB Output is correct
66 Correct 63 ms 9612 KB Output is correct
67 Correct 105 ms 9832 KB Output is correct
68 Correct 81 ms 9804 KB Output is correct
69 Correct 81 ms 9900 KB Output is correct
70 Correct 83 ms 9892 KB Output is correct
71 Correct 1 ms 2652 KB Output is correct
72 Correct 3 ms 2900 KB Output is correct
73 Correct 3 ms 2868 KB Output is correct
74 Correct 4 ms 2924 KB Output is correct
75 Correct 3 ms 2900 KB Output is correct
76 Correct 3 ms 2900 KB Output is correct
77 Correct 3 ms 2856 KB Output is correct
78 Correct 3 ms 2900 KB Output is correct
79 Correct 5 ms 2920 KB Output is correct
80 Correct 97 ms 9888 KB Output is correct
81 Correct 102 ms 9988 KB Output is correct
82 Correct 72 ms 9696 KB Output is correct
83 Correct 85 ms 9812 KB Output is correct
84 Correct 4 ms 2800 KB Output is correct
85 Correct 3 ms 2772 KB Output is correct
86 Correct 3 ms 2792 KB Output is correct
87 Correct 4 ms 2772 KB Output is correct
88 Correct 3 ms 2900 KB Output is correct
89 Correct 3 ms 2804 KB Output is correct
90 Correct 3 ms 2836 KB Output is correct
91 Correct 4 ms 2920 KB Output is correct
92 Correct 3 ms 2800 KB Output is correct
93 Correct 3 ms 2832 KB Output is correct
94 Correct 2 ms 2644 KB Output is correct
95 Correct 2 ms 2672 KB Output is correct
96 Correct 1 ms 2656 KB Output is correct
97 Correct 2 ms 2652 KB Output is correct
98 Correct 2 ms 2644 KB Output is correct
99 Correct 2 ms 2656 KB Output is correct
100 Correct 2 ms 2644 KB Output is correct
101 Correct 2 ms 2652 KB Output is correct
102 Correct 2 ms 2652 KB Output is correct
103 Correct 2 ms 2644 KB Output is correct
104 Correct 6 ms 3668 KB Output is correct
105 Correct 13 ms 4932 KB Output is correct
106 Correct 2 ms 2652 KB Output is correct
107 Correct 29 ms 6808 KB Output is correct
108 Correct 39 ms 8996 KB Output is correct
109 Correct 2 ms 2772 KB Output is correct
110 Correct 59 ms 9776 KB Output is correct
111 Correct 66 ms 11144 KB Output is correct
112 Correct 2 ms 2772 KB Output is correct
113 Correct 102 ms 16716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 7256 KB Output is correct
2 Incorrect 39 ms 7320 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 3 ms 2652 KB Output is correct
6 Correct 3 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2656 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2660 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 2 ms 2648 KB Output is correct
17 Correct 2 ms 2656 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 3 ms 2644 KB Output is correct
21 Correct 3 ms 2644 KB Output is correct
22 Correct 3 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 3 ms 2644 KB Output is correct
25 Correct 2 ms 2660 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 3 ms 2772 KB Output is correct
28 Correct 3 ms 2792 KB Output is correct
29 Incorrect 3 ms 2644 KB Output isn't correct
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 12324 KB Output is correct
2 Correct 48 ms 12104 KB Output is correct
3 Correct 46 ms 10472 KB Output is correct
4 Correct 8 ms 4064 KB Output is correct
5 Correct 8 ms 3412 KB Output is correct
6 Correct 13 ms 4808 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 22 ms 6852 KB Output is correct
9 Correct 28 ms 9016 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 41 ms 9836 KB Output is correct
12 Correct 54 ms 11116 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 3 ms 2644 KB Output is correct
18 Correct 3 ms 2652 KB Output is correct
19 Correct 3 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2656 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2660 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 2 ms 2648 KB Output is correct
30 Correct 2 ms 2656 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 2 ms 2644 KB Output is correct
33 Correct 3 ms 2644 KB Output is correct
34 Correct 3 ms 2644 KB Output is correct
35 Correct 3 ms 2644 KB Output is correct
36 Correct 2 ms 2644 KB Output is correct
37 Correct 3 ms 2644 KB Output is correct
38 Correct 2 ms 2660 KB Output is correct
39 Correct 49 ms 12512 KB Output is correct
40 Correct 44 ms 12216 KB Output is correct
41 Correct 32 ms 10600 KB Output is correct
42 Correct 8 ms 4220 KB Output is correct
43 Correct 2 ms 2644 KB Output is correct
44 Correct 2 ms 2644 KB Output is correct
45 Correct 2 ms 2652 KB Output is correct
46 Correct 2 ms 2644 KB Output is correct
47 Correct 2 ms 2644 KB Output is correct
48 Correct 2 ms 2652 KB Output is correct
49 Correct 3 ms 2644 KB Output is correct
50 Correct 2 ms 2644 KB Output is correct
51 Correct 3 ms 2644 KB Output is correct
52 Correct 2 ms 2656 KB Output is correct
53 Correct 2 ms 2644 KB Output is correct
54 Correct 2 ms 2644 KB Output is correct
55 Correct 2 ms 2644 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 65 ms 9864 KB Output is correct
58 Correct 69 ms 9872 KB Output is correct
59 Correct 108 ms 9808 KB Output is correct
60 Correct 88 ms 9896 KB Output is correct
61 Correct 75 ms 9820 KB Output is correct
62 Correct 62 ms 9832 KB Output is correct
63 Correct 84 ms 9656 KB Output is correct
64 Correct 68 ms 9660 KB Output is correct
65 Correct 64 ms 9668 KB Output is correct
66 Correct 63 ms 9612 KB Output is correct
67 Correct 105 ms 9832 KB Output is correct
68 Correct 81 ms 9804 KB Output is correct
69 Correct 81 ms 9900 KB Output is correct
70 Correct 83 ms 9892 KB Output is correct
71 Correct 1 ms 2652 KB Output is correct
72 Correct 3 ms 2900 KB Output is correct
73 Correct 3 ms 2868 KB Output is correct
74 Correct 4 ms 2924 KB Output is correct
75 Correct 3 ms 2900 KB Output is correct
76 Correct 3 ms 2900 KB Output is correct
77 Correct 3 ms 2856 KB Output is correct
78 Correct 3 ms 2900 KB Output is correct
79 Correct 5 ms 2920 KB Output is correct
80 Correct 97 ms 9888 KB Output is correct
81 Correct 102 ms 9988 KB Output is correct
82 Correct 72 ms 9696 KB Output is correct
83 Correct 85 ms 9812 KB Output is correct
84 Correct 4 ms 2800 KB Output is correct
85 Correct 3 ms 2772 KB Output is correct
86 Correct 3 ms 2792 KB Output is correct
87 Correct 4 ms 2772 KB Output is correct
88 Correct 3 ms 2900 KB Output is correct
89 Correct 3 ms 2804 KB Output is correct
90 Correct 3 ms 2836 KB Output is correct
91 Correct 4 ms 2920 KB Output is correct
92 Correct 3 ms 2800 KB Output is correct
93 Correct 3 ms 2832 KB Output is correct
94 Correct 2 ms 2644 KB Output is correct
95 Correct 2 ms 2672 KB Output is correct
96 Correct 1 ms 2656 KB Output is correct
97 Correct 2 ms 2652 KB Output is correct
98 Correct 2 ms 2644 KB Output is correct
99 Correct 2 ms 2656 KB Output is correct
100 Correct 2 ms 2644 KB Output is correct
101 Correct 2 ms 2652 KB Output is correct
102 Correct 2 ms 2652 KB Output is correct
103 Correct 2 ms 2644 KB Output is correct
104 Correct 6 ms 3668 KB Output is correct
105 Correct 13 ms 4932 KB Output is correct
106 Correct 2 ms 2652 KB Output is correct
107 Correct 29 ms 6808 KB Output is correct
108 Correct 39 ms 8996 KB Output is correct
109 Correct 2 ms 2772 KB Output is correct
110 Correct 59 ms 9776 KB Output is correct
111 Correct 66 ms 11144 KB Output is correct
112 Correct 2 ms 2772 KB Output is correct
113 Correct 102 ms 16716 KB Output is correct
114 Correct 41 ms 7256 KB Output is correct
115 Incorrect 39 ms 7320 KB Output isn't correct
116 Halted 0 ms 0 KB -