Submission #427374

# Submission time Handle Problem Language Result Execution time Memory
427374 2021-06-14T14:40:48 Z AmineWeslati Dreaming (IOI13_dreaming) C++14
59 / 100
1000 ms 15180 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int>vi; 
#define pb push_back
#define sz(v) (int)v.size()
#define all(x) begin(x),end(x)

typedef pair<int,int>pi;
#define fi first
#define se second
typedef vector<pi>vpi;
#define eb emplace_back

#define FOR(i,a,b) for(int i=a; i<b; i++)
#define ROF(i,a,b) for(int i=b-1; i>=a; i--)


void ckmax(int &x, int y){x=max(x,y);}
void ckmin(int &x, int y){x=min(x,y);}

const int MX=1e5+10;
//-----------------------------
int N,M; 
vpi adj[MX];

vi vis(MX,0),dist(MX,-1);
pi par[MX]; 

vi vv; 
void dfs(int u){
    vv.pb(u);
    vis[u]=1;
    for(auto it: adj[u]){
        int v=it.fi,w=it.se;
        if(dist[v]==-1){
            dist[v]=dist[u]+w;
            par[v]={u,w};
            dfs(v);
        }
    } 
}

int U,V,diam;

void solve(int u){
    vv.clear();
    dist[u]=0;    
    dfs(u);
    int v=u; 
    FOR(i,0,N) if(dist[i]!=-1 && dist[i]>dist[v]) v=i; 
    for(auto x: vv) dist[x]=-1;

    u=v; 

    vv.clear();
    dist[u]=0;
    dfs(u);
    v=u; 
    FOR(i,0,N) if(dist[i]!=-1 && dist[i]>dist[v]) v=i;
    diam=dist[v];

    for(auto x: vv) dist[x]=-1; 
    
    tie(U,V)={u,v};
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    ::N=N; ::M=M; 
    FOR(i,0,M){
        int u=A[i],v=B[i],w=T[i];
        adj[u].eb(v,w);
        adj[v].eb(u,w);
    }

    int ans=0;
    vi vec; 
    FOR(i,0,N) if(!vis[i]){
        solve(i);
        ckmax(ans,diam);
        
        int cur=0,mn=diam;
        while(U!=V){
            cur+=par[V].se; 
            V=par[V].fi;

            ckmin(mn,max(diam-cur,cur));
        }
        vec.pb(mn);
    }
    sort(all(vec));
    reverse(all(vec));


    if(sz(vec)>1)
        ckmax(ans,vec[0]+vec[1]+L);
    if(sz(vec)>2){
        ckmax(ans,vec[1]+vec[2]+L*2);
    }
    return ans; 
}

/*
12
8
2
0 8 4
8 2 2 
2 7 4
5 11 3
5 1 7
1 3 1
1 9 5
10 6 3

*/

/*
12
10
5

0 1 2
0 2 3
0 3 1
1 4 4 
1 5 1
3 6 6
7 8 5
7 9 5
5 10 5
5 11 5
*/
# Verdict Execution time Memory Grader output
1 Correct 58 ms 14164 KB Output is correct
2 Correct 63 ms 14204 KB Output is correct
3 Correct 37 ms 10520 KB Output is correct
4 Correct 9 ms 5068 KB Output is correct
5 Correct 8 ms 4300 KB Output is correct
6 Correct 18 ms 5836 KB Output is correct
7 Correct 3 ms 3404 KB Output is correct
8 Correct 30 ms 7208 KB Output is correct
9 Correct 36 ms 8656 KB Output is correct
10 Correct 3 ms 3532 KB Output is correct
11 Correct 58 ms 10224 KB Output is correct
12 Correct 68 ms 12228 KB Output is correct
13 Correct 4 ms 3532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3404 KB Output is correct
2 Correct 3 ms 3404 KB Output is correct
3 Correct 3 ms 3404 KB Output is correct
4 Correct 3 ms 3432 KB Output is correct
5 Correct 3 ms 3404 KB Output is correct
6 Correct 3 ms 3404 KB Output is correct
7 Correct 3 ms 3404 KB Output is correct
8 Correct 2 ms 3404 KB Output is correct
9 Correct 3 ms 3404 KB Output is correct
10 Correct 4 ms 3392 KB Output is correct
11 Correct 3 ms 3404 KB Output is correct
12 Correct 2 ms 3404 KB Output is correct
13 Correct 3 ms 3404 KB Output is correct
14 Correct 3 ms 3404 KB Output is correct
15 Correct 3 ms 3404 KB Output is correct
16 Correct 2 ms 3404 KB Output is correct
17 Correct 3 ms 3404 KB Output is correct
18 Correct 3 ms 3404 KB Output is correct
19 Correct 3 ms 3404 KB Output is correct
20 Correct 3 ms 3404 KB Output is correct
21 Correct 2 ms 3404 KB Output is correct
22 Correct 3 ms 3404 KB Output is correct
23 Correct 3 ms 3404 KB Output is correct
24 Correct 3 ms 3404 KB Output is correct
25 Correct 3 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 14164 KB Output is correct
2 Correct 63 ms 14204 KB Output is correct
3 Correct 37 ms 10520 KB Output is correct
4 Correct 9 ms 5068 KB Output is correct
5 Correct 8 ms 4300 KB Output is correct
6 Correct 18 ms 5836 KB Output is correct
7 Correct 3 ms 3404 KB Output is correct
8 Correct 30 ms 7208 KB Output is correct
9 Correct 36 ms 8656 KB Output is correct
10 Correct 3 ms 3532 KB Output is correct
11 Correct 58 ms 10224 KB Output is correct
12 Correct 68 ms 12228 KB Output is correct
13 Correct 4 ms 3532 KB Output is correct
14 Correct 3 ms 3404 KB Output is correct
15 Correct 3 ms 3404 KB Output is correct
16 Correct 3 ms 3404 KB Output is correct
17 Correct 3 ms 3432 KB Output is correct
18 Correct 3 ms 3404 KB Output is correct
19 Correct 3 ms 3404 KB Output is correct
20 Correct 3 ms 3404 KB Output is correct
21 Correct 2 ms 3404 KB Output is correct
22 Correct 3 ms 3404 KB Output is correct
23 Correct 4 ms 3392 KB Output is correct
24 Correct 3 ms 3404 KB Output is correct
25 Correct 2 ms 3404 KB Output is correct
26 Correct 3 ms 3404 KB Output is correct
27 Correct 3 ms 3404 KB Output is correct
28 Correct 3 ms 3404 KB Output is correct
29 Correct 2 ms 3404 KB Output is correct
30 Correct 3 ms 3404 KB Output is correct
31 Correct 3 ms 3404 KB Output is correct
32 Correct 3 ms 3404 KB Output is correct
33 Correct 3 ms 3404 KB Output is correct
34 Correct 2 ms 3404 KB Output is correct
35 Correct 3 ms 3404 KB Output is correct
36 Correct 3 ms 3404 KB Output is correct
37 Correct 3 ms 3404 KB Output is correct
38 Correct 3 ms 3404 KB Output is correct
39 Correct 84 ms 14228 KB Output is correct
40 Correct 71 ms 14196 KB Output is correct
41 Correct 39 ms 10536 KB Output is correct
42 Correct 12 ms 5068 KB Output is correct
43 Correct 3 ms 3404 KB Output is correct
44 Correct 2 ms 3404 KB Output is correct
45 Correct 3 ms 3404 KB Output is correct
46 Correct 2 ms 3404 KB Output is correct
47 Correct 2 ms 3404 KB Output is correct
48 Correct 3 ms 3404 KB Output is correct
49 Correct 3 ms 3404 KB Output is correct
50 Correct 3 ms 3404 KB Output is correct
51 Correct 3 ms 3404 KB Output is correct
52 Correct 2 ms 3404 KB Output is correct
53 Correct 3 ms 3404 KB Output is correct
54 Correct 4 ms 3404 KB Output is correct
55 Correct 3 ms 3404 KB Output is correct
56 Correct 3 ms 3404 KB Output is correct
57 Correct 88 ms 9960 KB Output is correct
58 Correct 104 ms 9720 KB Output is correct
59 Correct 92 ms 9884 KB Output is correct
60 Correct 97 ms 9548 KB Output is correct
61 Correct 117 ms 9860 KB Output is correct
62 Correct 82 ms 9560 KB Output is correct
63 Correct 82 ms 9608 KB Output is correct
64 Correct 78 ms 9608 KB Output is correct
65 Correct 80 ms 9604 KB Output is correct
66 Correct 92 ms 9704 KB Output is correct
67 Correct 98 ms 9872 KB Output is correct
68 Correct 109 ms 9912 KB Output is correct
69 Correct 115 ms 9672 KB Output is correct
70 Correct 88 ms 9540 KB Output is correct
71 Correct 3 ms 3404 KB Output is correct
72 Correct 4 ms 3616 KB Output is correct
73 Correct 4 ms 3596 KB Output is correct
74 Correct 4 ms 3660 KB Output is correct
75 Correct 4 ms 3532 KB Output is correct
76 Correct 6 ms 3660 KB Output is correct
77 Correct 5 ms 3660 KB Output is correct
78 Correct 4 ms 3532 KB Output is correct
79 Correct 4 ms 3660 KB Output is correct
80 Correct 84 ms 9792 KB Output is correct
81 Correct 126 ms 9820 KB Output is correct
82 Correct 113 ms 9760 KB Output is correct
83 Correct 105 ms 9776 KB Output is correct
84 Correct 5 ms 3532 KB Output is correct
85 Correct 3 ms 3532 KB Output is correct
86 Correct 3 ms 3532 KB Output is correct
87 Correct 4 ms 3532 KB Output is correct
88 Correct 3 ms 3532 KB Output is correct
89 Correct 3 ms 3532 KB Output is correct
90 Correct 4 ms 3532 KB Output is correct
91 Correct 4 ms 3660 KB Output is correct
92 Correct 4 ms 3532 KB Output is correct
93 Correct 4 ms 3532 KB Output is correct
94 Correct 3 ms 3404 KB Output is correct
95 Correct 3 ms 3404 KB Output is correct
96 Correct 3 ms 3404 KB Output is correct
97 Correct 2 ms 3424 KB Output is correct
98 Correct 3 ms 3404 KB Output is correct
99 Correct 3 ms 3404 KB Output is correct
100 Correct 3 ms 3404 KB Output is correct
101 Correct 3 ms 3404 KB Output is correct
102 Correct 2 ms 3404 KB Output is correct
103 Correct 3 ms 3404 KB Output is correct
104 Correct 11 ms 4224 KB Output is correct
105 Correct 15 ms 5796 KB Output is correct
106 Correct 3 ms 3404 KB Output is correct
107 Correct 28 ms 7128 KB Output is correct
108 Correct 42 ms 8772 KB Output is correct
109 Correct 4 ms 3524 KB Output is correct
110 Correct 60 ms 10184 KB Output is correct
111 Correct 69 ms 12292 KB Output is correct
112 Correct 3 ms 3492 KB Output is correct
113 Correct 98 ms 15180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1078 ms 6496 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3404 KB Output is correct
2 Correct 3 ms 3404 KB Output is correct
3 Correct 3 ms 3404 KB Output is correct
4 Correct 3 ms 3432 KB Output is correct
5 Correct 3 ms 3404 KB Output is correct
6 Correct 3 ms 3404 KB Output is correct
7 Correct 3 ms 3404 KB Output is correct
8 Correct 2 ms 3404 KB Output is correct
9 Correct 3 ms 3404 KB Output is correct
10 Correct 4 ms 3392 KB Output is correct
11 Correct 3 ms 3404 KB Output is correct
12 Correct 2 ms 3404 KB Output is correct
13 Correct 3 ms 3404 KB Output is correct
14 Correct 3 ms 3404 KB Output is correct
15 Correct 3 ms 3404 KB Output is correct
16 Correct 2 ms 3404 KB Output is correct
17 Correct 3 ms 3404 KB Output is correct
18 Correct 3 ms 3404 KB Output is correct
19 Correct 3 ms 3404 KB Output is correct
20 Correct 3 ms 3404 KB Output is correct
21 Correct 2 ms 3404 KB Output is correct
22 Correct 3 ms 3404 KB Output is correct
23 Correct 3 ms 3404 KB Output is correct
24 Correct 3 ms 3404 KB Output is correct
25 Correct 3 ms 3404 KB Output is correct
26 Correct 3 ms 3404 KB Output is correct
27 Correct 5 ms 3532 KB Output is correct
28 Correct 9 ms 3532 KB Output is correct
29 Correct 3 ms 3404 KB Output is correct
30 Correct 5 ms 3532 KB Output is correct
31 Correct 9 ms 3532 KB Output is correct
32 Correct 4 ms 3404 KB Output is correct
33 Correct 6 ms 3532 KB Output is correct
34 Correct 9 ms 3532 KB Output is correct
35 Correct 3 ms 3404 KB Output is correct
36 Correct 2 ms 3404 KB Output is correct
37 Correct 3 ms 3404 KB Output is correct
38 Correct 3 ms 3404 KB Output is correct
39 Correct 2 ms 3404 KB Output is correct
40 Correct 3 ms 3404 KB Output is correct
41 Correct 3 ms 3404 KB Output is correct
42 Correct 2 ms 3404 KB Output is correct
43 Correct 2 ms 3404 KB Output is correct
44 Correct 2 ms 3404 KB Output is correct
45 Correct 2 ms 3404 KB Output is correct
46 Correct 2 ms 3404 KB Output is correct
47 Correct 2 ms 3404 KB Output is correct
48 Correct 2 ms 3404 KB Output is correct
49 Correct 2 ms 3404 KB Output is correct
50 Correct 2 ms 3404 KB Output is correct
51 Correct 3 ms 3404 KB Output is correct
52 Correct 3 ms 3404 KB Output is correct
53 Correct 2 ms 3404 KB Output is correct
54 Correct 4 ms 3788 KB Output is correct
55 Correct 4 ms 3788 KB Output is correct
56 Correct 13 ms 3588 KB Output is correct
57 Correct 26 ms 3540 KB Output is correct
58 Correct 4 ms 3532 KB Output is correct
59 Correct 4 ms 3648 KB Output is correct
60 Correct 17 ms 3532 KB Output is correct
61 Correct 20 ms 3532 KB Output is correct
62 Correct 4 ms 3532 KB Output is correct
63 Correct 4 ms 3532 KB Output is correct
64 Correct 24 ms 3536 KB Output is correct
65 Correct 12 ms 3592 KB Output is correct
66 Correct 4 ms 3660 KB Output is correct
67 Correct 4 ms 3532 KB Output is correct
68 Correct 12 ms 3532 KB Output is correct
69 Correct 11 ms 3532 KB Output is correct
70 Correct 18 ms 3560 KB Output is correct
71 Correct 22 ms 3532 KB Output is correct
72 Correct 4 ms 3660 KB Output is correct
73 Correct 4 ms 3660 KB Output is correct
74 Correct 6 ms 3532 KB Output is correct
75 Correct 6 ms 3532 KB Output is correct
76 Correct 4 ms 3532 KB Output is correct
77 Correct 4 ms 3532 KB Output is correct
78 Correct 18 ms 3564 KB Output is correct
79 Correct 18 ms 3568 KB Output is correct
80 Correct 30 ms 3516 KB Output is correct
81 Correct 34 ms 3404 KB Output is correct
82 Correct 8 ms 3532 KB Output is correct
83 Correct 6 ms 3556 KB Output is correct
84 Correct 18 ms 3532 KB Output is correct
85 Correct 23 ms 3404 KB Output is correct
86 Correct 12 ms 3596 KB Output is correct
87 Correct 6 ms 3532 KB Output is correct
88 Correct 13 ms 3532 KB Output is correct
89 Correct 13 ms 3592 KB Output is correct
90 Correct 17 ms 3572 KB Output is correct
91 Correct 18 ms 3532 KB Output is correct
92 Correct 3 ms 3532 KB Output is correct
93 Correct 3 ms 3532 KB Output is correct
94 Correct 4 ms 3532 KB Output is correct
95 Correct 3 ms 3532 KB Output is correct
96 Correct 4 ms 3532 KB Output is correct
97 Correct 4 ms 3532 KB Output is correct
98 Correct 5 ms 3532 KB Output is correct
99 Correct 4 ms 3532 KB Output is correct
100 Correct 4 ms 3532 KB Output is correct
101 Correct 4 ms 3532 KB Output is correct
102 Correct 3 ms 3404 KB Output is correct
103 Correct 3 ms 3404 KB Output is correct
104 Correct 3 ms 3404 KB Output is correct
105 Correct 2 ms 3404 KB Output is correct
106 Correct 3 ms 3344 KB Output is correct
107 Correct 3 ms 3404 KB Output is correct
108 Correct 2 ms 3404 KB Output is correct
109 Correct 2 ms 3404 KB Output is correct
110 Correct 2 ms 3404 KB Output is correct
111 Correct 3 ms 3404 KB Output is correct
112 Correct 3 ms 3404 KB Output is correct
113 Correct 3 ms 3532 KB Output is correct
114 Correct 3 ms 3532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 14164 KB Output is correct
2 Correct 63 ms 14204 KB Output is correct
3 Correct 37 ms 10520 KB Output is correct
4 Correct 9 ms 5068 KB Output is correct
5 Correct 8 ms 4300 KB Output is correct
6 Correct 18 ms 5836 KB Output is correct
7 Correct 3 ms 3404 KB Output is correct
8 Correct 30 ms 7208 KB Output is correct
9 Correct 36 ms 8656 KB Output is correct
10 Correct 3 ms 3532 KB Output is correct
11 Correct 58 ms 10224 KB Output is correct
12 Correct 68 ms 12228 KB Output is correct
13 Correct 4 ms 3532 KB Output is correct
14 Correct 3 ms 3404 KB Output is correct
15 Correct 3 ms 3404 KB Output is correct
16 Correct 3 ms 3404 KB Output is correct
17 Correct 3 ms 3432 KB Output is correct
18 Correct 3 ms 3404 KB Output is correct
19 Correct 3 ms 3404 KB Output is correct
20 Correct 3 ms 3404 KB Output is correct
21 Correct 2 ms 3404 KB Output is correct
22 Correct 3 ms 3404 KB Output is correct
23 Correct 4 ms 3392 KB Output is correct
24 Correct 3 ms 3404 KB Output is correct
25 Correct 2 ms 3404 KB Output is correct
26 Correct 3 ms 3404 KB Output is correct
27 Correct 3 ms 3404 KB Output is correct
28 Correct 3 ms 3404 KB Output is correct
29 Correct 2 ms 3404 KB Output is correct
30 Correct 3 ms 3404 KB Output is correct
31 Correct 3 ms 3404 KB Output is correct
32 Correct 3 ms 3404 KB Output is correct
33 Correct 3 ms 3404 KB Output is correct
34 Correct 2 ms 3404 KB Output is correct
35 Correct 3 ms 3404 KB Output is correct
36 Correct 3 ms 3404 KB Output is correct
37 Correct 3 ms 3404 KB Output is correct
38 Correct 3 ms 3404 KB Output is correct
39 Correct 84 ms 14228 KB Output is correct
40 Correct 71 ms 14196 KB Output is correct
41 Correct 39 ms 10536 KB Output is correct
42 Correct 12 ms 5068 KB Output is correct
43 Correct 3 ms 3404 KB Output is correct
44 Correct 2 ms 3404 KB Output is correct
45 Correct 3 ms 3404 KB Output is correct
46 Correct 2 ms 3404 KB Output is correct
47 Correct 2 ms 3404 KB Output is correct
48 Correct 3 ms 3404 KB Output is correct
49 Correct 3 ms 3404 KB Output is correct
50 Correct 3 ms 3404 KB Output is correct
51 Correct 3 ms 3404 KB Output is correct
52 Correct 2 ms 3404 KB Output is correct
53 Correct 3 ms 3404 KB Output is correct
54 Correct 4 ms 3404 KB Output is correct
55 Correct 3 ms 3404 KB Output is correct
56 Correct 3 ms 3404 KB Output is correct
57 Correct 88 ms 9960 KB Output is correct
58 Correct 104 ms 9720 KB Output is correct
59 Correct 92 ms 9884 KB Output is correct
60 Correct 97 ms 9548 KB Output is correct
61 Correct 117 ms 9860 KB Output is correct
62 Correct 82 ms 9560 KB Output is correct
63 Correct 82 ms 9608 KB Output is correct
64 Correct 78 ms 9608 KB Output is correct
65 Correct 80 ms 9604 KB Output is correct
66 Correct 92 ms 9704 KB Output is correct
67 Correct 98 ms 9872 KB Output is correct
68 Correct 109 ms 9912 KB Output is correct
69 Correct 115 ms 9672 KB Output is correct
70 Correct 88 ms 9540 KB Output is correct
71 Correct 3 ms 3404 KB Output is correct
72 Correct 4 ms 3616 KB Output is correct
73 Correct 4 ms 3596 KB Output is correct
74 Correct 4 ms 3660 KB Output is correct
75 Correct 4 ms 3532 KB Output is correct
76 Correct 6 ms 3660 KB Output is correct
77 Correct 5 ms 3660 KB Output is correct
78 Correct 4 ms 3532 KB Output is correct
79 Correct 4 ms 3660 KB Output is correct
80 Correct 84 ms 9792 KB Output is correct
81 Correct 126 ms 9820 KB Output is correct
82 Correct 113 ms 9760 KB Output is correct
83 Correct 105 ms 9776 KB Output is correct
84 Correct 5 ms 3532 KB Output is correct
85 Correct 3 ms 3532 KB Output is correct
86 Correct 3 ms 3532 KB Output is correct
87 Correct 4 ms 3532 KB Output is correct
88 Correct 3 ms 3532 KB Output is correct
89 Correct 3 ms 3532 KB Output is correct
90 Correct 4 ms 3532 KB Output is correct
91 Correct 4 ms 3660 KB Output is correct
92 Correct 4 ms 3532 KB Output is correct
93 Correct 4 ms 3532 KB Output is correct
94 Correct 3 ms 3404 KB Output is correct
95 Correct 3 ms 3404 KB Output is correct
96 Correct 3 ms 3404 KB Output is correct
97 Correct 2 ms 3424 KB Output is correct
98 Correct 3 ms 3404 KB Output is correct
99 Correct 3 ms 3404 KB Output is correct
100 Correct 3 ms 3404 KB Output is correct
101 Correct 3 ms 3404 KB Output is correct
102 Correct 2 ms 3404 KB Output is correct
103 Correct 3 ms 3404 KB Output is correct
104 Correct 11 ms 4224 KB Output is correct
105 Correct 15 ms 5796 KB Output is correct
106 Correct 3 ms 3404 KB Output is correct
107 Correct 28 ms 7128 KB Output is correct
108 Correct 42 ms 8772 KB Output is correct
109 Correct 4 ms 3524 KB Output is correct
110 Correct 60 ms 10184 KB Output is correct
111 Correct 69 ms 12292 KB Output is correct
112 Correct 3 ms 3492 KB Output is correct
113 Correct 98 ms 15180 KB Output is correct
114 Execution timed out 1078 ms 6496 KB Time limit exceeded
115 Halted 0 ms 0 KB -