Submission #492184

# Submission time Handle Problem Language Result Execution time Memory
492184 2021-12-05T20:30:43 Z aci Dreaming (IOI13_dreaming) C++14
47 / 100
101 ms 17468 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
#define INF 1e12
typedef long long ll;
typedef pair<ll, ll> pi;

vector<vector<pi>> t;
vector<bool> used;
vector<bool> used2;


int n, m, l;
ll d, r;
vector<pi> dist;
vector<int> el;

void dfs1(int u, int p)
{
    used[u] = 1;
    el.push_back(u);
    for (pi v : t[u])
    {
        if(v.first!=p && !used[v.first])
        {
            dist[v.first].first = dist[u].first + v.second;
            dfs1(v.first, u);
        }
    }
}

void dfs2(int u, int p)
{
    used2[u] = 1;
    for (pi v : t[u])
    {
        if(v.first!=p && !used2[v.first])
        {
            dist[v.first].second = dist[u].second + v.second;
            dfs2(v.first, u);
        }
    }
}
void dfs3(int u, int p)
{
    used2[u] = 1;
    for (pi v : t[u])
    {
        if(v.first!=p && !used2[v.first])
        {
            dist[v.first].first = dist[u].first + v.second;
            dfs3(v.first, u);
        }
    }
}

bool cmp(pi a, pi b)
{
    
    return (a.second > b.second);
}


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

    t.resize(n);
    used.resize(n, 0);
    dist.resize(n, {-1, -1});
    used2.resize(n, 0);

    for (int i=0; i<m; i++)
    {
        int x, y, w;
        x = A[i];
        y = B[i];
        w = T[i];

        t[x].push_back({y, w});
        t[y].push_back({x, w});
    }

    vector<pi> comp; //diametro massimo e profondità

    for (int i=0; i<n; i++)
    {
        
        if(!used[i])
        {
            
            dist[i].first =0;//parto nodo a caso
            el.clear(); 
            dfs1(i, i);
            
            used2.assign(n, 0); //rifaccio dfs
            int ind=i, mx = 0;
            
            //cerco nodo a distanza massima 
            for (int j : el)
            {
                if(dist[j].first > mx)
                {
                    mx = dist[j].first;
                    ind = j;
                }
            }


            dist[ind].second = 0;
            dfs2(ind, ind);
            
            d = 0;
            //trovo diamentro e suoi estremi
            for (int j : el)
            {
                if(dist[j].second > d)
                {
                    d = dist[j].second;
                    ind = j;
                }
            }
            //rifaccio fs anche su altro estremo
            used2.assign(n, 0);
            dist[ind].first = 0;
            r = INF;
            dfs3(ind, ind);
            //for (int j : el) //cout<<j<<" "<< dist[j].first<<" "<<dist[j].second<<endl;
            for (int j : el)
            {
                if(dist[j].first==-1) dist[j].first = INF;
                if(dist[j].second==-1) dist[j].second = INF;
                r = min(r, max(dist[j].first, dist[j].second));
            }
            comp.push_back({d, r});

        }
    }
    
    sort(comp.begin(), comp.end(), cmp);
    ll res = 0;
    for (auto x : comp) res = max(res, x.first); 
    ll a, b;
    if(comp.size()==1) a = 0;
    else a = comp[0].second+l+comp[1].second;
    if(comp.size()==2) b = 0;
    else b = (2*l+comp[1].second+comp[2].second);
    res = max(res, max( a, b));

    //for (auto x : comp) //cout<< x.first<<" "<<x.second<<endl;


    return res;

}
# Verdict Execution time Memory Grader output
1 Correct 47 ms 15428 KB Output is correct
2 Correct 48 ms 15352 KB Output is correct
3 Correct 32 ms 10248 KB Output is correct
4 Correct 6 ms 2520 KB Output is correct
5 Correct 5 ms 1740 KB Output is correct
6 Correct 11 ms 3780 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 24 ms 6188 KB Output is correct
9 Correct 35 ms 8168 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 53 ms 10764 KB Output is correct
12 Correct 62 ms 13228 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 15428 KB Output is correct
2 Correct 48 ms 15352 KB Output is correct
3 Correct 32 ms 10248 KB Output is correct
4 Correct 6 ms 2520 KB Output is correct
5 Correct 5 ms 1740 KB Output is correct
6 Correct 11 ms 3780 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 24 ms 6188 KB Output is correct
9 Correct 35 ms 8168 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 53 ms 10764 KB Output is correct
12 Correct 62 ms 13228 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 50 ms 15320 KB Output is correct
40 Correct 49 ms 15316 KB Output is correct
41 Correct 33 ms 10200 KB Output is correct
42 Correct 6 ms 2508 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 0 ms 204 KB Output is correct
45 Correct 1 ms 204 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 0 ms 204 KB Output is correct
52 Correct 1 ms 204 KB Output is correct
53 Correct 0 ms 204 KB Output is correct
54 Correct 0 ms 204 KB Output is correct
55 Correct 0 ms 204 KB Output is correct
56 Correct 0 ms 204 KB Output is correct
57 Correct 82 ms 11936 KB Output is correct
58 Correct 76 ms 11564 KB Output is correct
59 Correct 75 ms 11664 KB Output is correct
60 Correct 73 ms 11376 KB Output is correct
61 Correct 70 ms 11460 KB Output is correct
62 Correct 78 ms 11216 KB Output is correct
63 Correct 64 ms 11160 KB Output is correct
64 Correct 65 ms 11176 KB Output is correct
65 Correct 64 ms 11132 KB Output is correct
66 Correct 67 ms 11084 KB Output is correct
67 Correct 74 ms 11568 KB Output is correct
68 Correct 72 ms 11680 KB Output is correct
69 Correct 81 ms 11332 KB Output is correct
70 Correct 75 ms 11332 KB Output is correct
71 Correct 0 ms 204 KB Output is correct
72 Correct 2 ms 636 KB Output is correct
73 Correct 2 ms 588 KB Output is correct
74 Correct 2 ms 588 KB Output is correct
75 Correct 1 ms 588 KB Output is correct
76 Correct 2 ms 588 KB Output is correct
77 Correct 2 ms 588 KB Output is correct
78 Correct 2 ms 588 KB Output is correct
79 Correct 2 ms 588 KB Output is correct
80 Correct 74 ms 11584 KB Output is correct
81 Correct 72 ms 11600 KB Output is correct
82 Correct 78 ms 11460 KB Output is correct
83 Correct 75 ms 11440 KB Output is correct
84 Correct 1 ms 460 KB Output is correct
85 Correct 1 ms 460 KB Output is correct
86 Correct 1 ms 460 KB Output is correct
87 Correct 1 ms 588 KB Output is correct
88 Correct 2 ms 588 KB Output is correct
89 Correct 1 ms 588 KB Output is correct
90 Correct 2 ms 588 KB Output is correct
91 Correct 1 ms 588 KB Output is correct
92 Correct 1 ms 588 KB Output is correct
93 Correct 1 ms 588 KB Output is correct
94 Correct 0 ms 204 KB Output is correct
95 Correct 0 ms 204 KB Output is correct
96 Correct 0 ms 204 KB Output is correct
97 Correct 0 ms 204 KB Output is correct
98 Correct 0 ms 204 KB Output is correct
99 Correct 0 ms 204 KB Output is correct
100 Correct 1 ms 204 KB Output is correct
101 Correct 1 ms 204 KB Output is correct
102 Correct 0 ms 204 KB Output is correct
103 Correct 0 ms 204 KB Output is correct
104 Correct 5 ms 1740 KB Output is correct
105 Correct 11 ms 3788 KB Output is correct
106 Correct 0 ms 332 KB Output is correct
107 Correct 29 ms 6132 KB Output is correct
108 Correct 32 ms 8256 KB Output is correct
109 Correct 1 ms 332 KB Output is correct
110 Correct 55 ms 10788 KB Output is correct
111 Correct 82 ms 13228 KB Output is correct
112 Correct 1 ms 332 KB Output is correct
113 Correct 101 ms 17468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 7440 KB Output is correct
2 Correct 59 ms 7412 KB Output is correct
3 Correct 54 ms 7356 KB Output is correct
4 Correct 56 ms 7480 KB Output is correct
5 Correct 54 ms 7484 KB Output is correct
6 Correct 66 ms 8848 KB Output is correct
7 Correct 59 ms 7712 KB Output is correct
8 Correct 53 ms 7284 KB Output is correct
9 Correct 53 ms 7244 KB Output is correct
10 Correct 59 ms 7616 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 64 ms 6328 KB Output is correct
13 Correct 63 ms 6392 KB Output is correct
14 Correct 69 ms 6480 KB Output is correct
15 Correct 64 ms 6328 KB Output is correct
16 Correct 63 ms 6420 KB Output is correct
17 Correct 63 ms 6356 KB Output is correct
18 Correct 63 ms 6400 KB Output is correct
19 Correct 64 ms 6392 KB Output is correct
20 Incorrect 0 ms 204 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 588 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 588 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 1 ms 588 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 0 ms 204 KB Output is correct
45 Correct 0 ms 204 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 0 ms 204 KB Output is correct
52 Incorrect 0 ms 204 KB Output isn't correct
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 47 ms 15428 KB Output is correct
2 Correct 48 ms 15352 KB Output is correct
3 Correct 32 ms 10248 KB Output is correct
4 Correct 6 ms 2520 KB Output is correct
5 Correct 5 ms 1740 KB Output is correct
6 Correct 11 ms 3780 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 24 ms 6188 KB Output is correct
9 Correct 35 ms 8168 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 53 ms 10764 KB Output is correct
12 Correct 62 ms 13228 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 50 ms 15320 KB Output is correct
40 Correct 49 ms 15316 KB Output is correct
41 Correct 33 ms 10200 KB Output is correct
42 Correct 6 ms 2508 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 0 ms 204 KB Output is correct
45 Correct 1 ms 204 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 0 ms 204 KB Output is correct
52 Correct 1 ms 204 KB Output is correct
53 Correct 0 ms 204 KB Output is correct
54 Correct 0 ms 204 KB Output is correct
55 Correct 0 ms 204 KB Output is correct
56 Correct 0 ms 204 KB Output is correct
57 Correct 82 ms 11936 KB Output is correct
58 Correct 76 ms 11564 KB Output is correct
59 Correct 75 ms 11664 KB Output is correct
60 Correct 73 ms 11376 KB Output is correct
61 Correct 70 ms 11460 KB Output is correct
62 Correct 78 ms 11216 KB Output is correct
63 Correct 64 ms 11160 KB Output is correct
64 Correct 65 ms 11176 KB Output is correct
65 Correct 64 ms 11132 KB Output is correct
66 Correct 67 ms 11084 KB Output is correct
67 Correct 74 ms 11568 KB Output is correct
68 Correct 72 ms 11680 KB Output is correct
69 Correct 81 ms 11332 KB Output is correct
70 Correct 75 ms 11332 KB Output is correct
71 Correct 0 ms 204 KB Output is correct
72 Correct 2 ms 636 KB Output is correct
73 Correct 2 ms 588 KB Output is correct
74 Correct 2 ms 588 KB Output is correct
75 Correct 1 ms 588 KB Output is correct
76 Correct 2 ms 588 KB Output is correct
77 Correct 2 ms 588 KB Output is correct
78 Correct 2 ms 588 KB Output is correct
79 Correct 2 ms 588 KB Output is correct
80 Correct 74 ms 11584 KB Output is correct
81 Correct 72 ms 11600 KB Output is correct
82 Correct 78 ms 11460 KB Output is correct
83 Correct 75 ms 11440 KB Output is correct
84 Correct 1 ms 460 KB Output is correct
85 Correct 1 ms 460 KB Output is correct
86 Correct 1 ms 460 KB Output is correct
87 Correct 1 ms 588 KB Output is correct
88 Correct 2 ms 588 KB Output is correct
89 Correct 1 ms 588 KB Output is correct
90 Correct 2 ms 588 KB Output is correct
91 Correct 1 ms 588 KB Output is correct
92 Correct 1 ms 588 KB Output is correct
93 Correct 1 ms 588 KB Output is correct
94 Correct 0 ms 204 KB Output is correct
95 Correct 0 ms 204 KB Output is correct
96 Correct 0 ms 204 KB Output is correct
97 Correct 0 ms 204 KB Output is correct
98 Correct 0 ms 204 KB Output is correct
99 Correct 0 ms 204 KB Output is correct
100 Correct 1 ms 204 KB Output is correct
101 Correct 1 ms 204 KB Output is correct
102 Correct 0 ms 204 KB Output is correct
103 Correct 0 ms 204 KB Output is correct
104 Correct 5 ms 1740 KB Output is correct
105 Correct 11 ms 3788 KB Output is correct
106 Correct 0 ms 332 KB Output is correct
107 Correct 29 ms 6132 KB Output is correct
108 Correct 32 ms 8256 KB Output is correct
109 Correct 1 ms 332 KB Output is correct
110 Correct 55 ms 10788 KB Output is correct
111 Correct 82 ms 13228 KB Output is correct
112 Correct 1 ms 332 KB Output is correct
113 Correct 101 ms 17468 KB Output is correct
114 Correct 54 ms 7440 KB Output is correct
115 Correct 59 ms 7412 KB Output is correct
116 Correct 54 ms 7356 KB Output is correct
117 Correct 56 ms 7480 KB Output is correct
118 Correct 54 ms 7484 KB Output is correct
119 Correct 66 ms 8848 KB Output is correct
120 Correct 59 ms 7712 KB Output is correct
121 Correct 53 ms 7284 KB Output is correct
122 Correct 53 ms 7244 KB Output is correct
123 Correct 59 ms 7616 KB Output is correct
124 Correct 0 ms 204 KB Output is correct
125 Correct 64 ms 6328 KB Output is correct
126 Correct 63 ms 6392 KB Output is correct
127 Correct 69 ms 6480 KB Output is correct
128 Correct 64 ms 6328 KB Output is correct
129 Correct 63 ms 6420 KB Output is correct
130 Correct 63 ms 6356 KB Output is correct
131 Correct 63 ms 6400 KB Output is correct
132 Correct 64 ms 6392 KB Output is correct
133 Incorrect 0 ms 204 KB Output isn't correct
134 Halted 0 ms 0 KB -