Submission #492186

# Submission time Handle Problem Language Result Execution time Memory
492186 2021-12-05T20:33:11 Z aci Dreaming (IOI13_dreaming) C++14
47 / 100
131 ms 17284 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);
        }
    }
}




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({r, d});

        }
    }
    
    sort(comp.begin(), comp.end(), greater<pi>());
    ll res = 0;
    for (auto x : comp) res = max(res, x.second); 
    ll a, b;
    if(comp.size()==1) a = 0;
    else a = comp[0].first+l+comp[1].first;
    if(comp.size()==2) b = 0;
    else b = (2*l+comp[1].first+comp[2].first);
    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 50 ms 15428 KB Output is correct
2 Correct 48 ms 15280 KB Output is correct
3 Correct 39 ms 10176 KB Output is correct
4 Correct 6 ms 2472 KB Output is correct
5 Correct 5 ms 1688 KB Output is correct
6 Correct 13 ms 3788 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 23 ms 6220 KB Output is correct
9 Correct 47 ms 8220 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 59 ms 10728 KB Output is correct
12 Correct 72 ms 13236 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 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 1 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 1 ms 204 KB Output is correct
16 Correct 1 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
# Verdict Execution time Memory Grader output
1 Correct 50 ms 15428 KB Output is correct
2 Correct 48 ms 15280 KB Output is correct
3 Correct 39 ms 10176 KB Output is correct
4 Correct 6 ms 2472 KB Output is correct
5 Correct 5 ms 1688 KB Output is correct
6 Correct 13 ms 3788 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 23 ms 6220 KB Output is correct
9 Correct 47 ms 8220 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 59 ms 10728 KB Output is correct
12 Correct 72 ms 13236 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 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 1 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 1 ms 204 KB Output is correct
29 Correct 1 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 0 ms 204 KB Output is correct
39 Correct 48 ms 15360 KB Output is correct
40 Correct 48 ms 15376 KB Output is correct
41 Correct 29 ms 10184 KB Output is correct
42 Correct 6 ms 2508 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 1 ms 204 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 1 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 1 ms 204 KB Output is correct
52 Correct 0 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 78 ms 11936 KB Output is correct
58 Correct 90 ms 11648 KB Output is correct
59 Correct 91 ms 11580 KB Output is correct
60 Correct 131 ms 11356 KB Output is correct
61 Correct 74 ms 11456 KB Output is correct
62 Correct 70 ms 11212 KB Output is correct
63 Correct 92 ms 11152 KB Output is correct
64 Correct 73 ms 11176 KB Output is correct
65 Correct 70 ms 11168 KB Output is correct
66 Correct 65 ms 11200 KB Output is correct
67 Correct 86 ms 11700 KB Output is correct
68 Correct 82 ms 11668 KB Output is correct
69 Correct 97 ms 11308 KB Output is correct
70 Correct 76 ms 11332 KB Output is correct
71 Correct 0 ms 204 KB Output is correct
72 Correct 2 ms 588 KB Output is correct
73 Correct 2 ms 588 KB Output is correct
74 Correct 2 ms 588 KB Output is correct
75 Correct 2 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 3 ms 588 KB Output is correct
79 Correct 3 ms 588 KB Output is correct
80 Correct 79 ms 11640 KB Output is correct
81 Correct 76 ms 11568 KB Output is correct
82 Correct 70 ms 11436 KB Output is correct
83 Correct 69 ms 11420 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 1 ms 588 KB Output is correct
89 Correct 2 ms 588 KB Output is correct
90 Correct 2 ms 588 KB Output is correct
91 Correct 2 ms 588 KB Output is correct
92 Correct 2 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 0 ms 204 KB Output is correct
101 Correct 0 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 12 ms 3788 KB Output is correct
106 Correct 1 ms 332 KB Output is correct
107 Correct 23 ms 6092 KB Output is correct
108 Correct 31 ms 8260 KB Output is correct
109 Correct 1 ms 332 KB Output is correct
110 Correct 58 ms 10824 KB Output is correct
111 Correct 62 ms 13228 KB Output is correct
112 Correct 1 ms 332 KB Output is correct
113 Correct 93 ms 17284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 7444 KB Output is correct
2 Correct 58 ms 7396 KB Output is correct
3 Correct 81 ms 7416 KB Output is correct
4 Correct 62 ms 7460 KB Output is correct
5 Correct 54 ms 7412 KB Output is correct
6 Correct 67 ms 8796 KB Output is correct
7 Correct 61 ms 7704 KB Output is correct
8 Correct 54 ms 7324 KB Output is correct
9 Correct 77 ms 7300 KB Output is correct
10 Correct 58 ms 7616 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 67 ms 6328 KB Output is correct
13 Correct 66 ms 6420 KB Output is correct
14 Correct 64 ms 6328 KB Output is correct
15 Correct 63 ms 6352 KB Output is correct
16 Correct 66 ms 6416 KB Output is correct
17 Correct 63 ms 6392 KB Output is correct
18 Correct 64 ms 6372 KB Output is correct
19 Correct 71 ms 6356 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 1 ms 204 KB Output is correct
2 Correct 0 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 1 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 1 ms 204 KB Output is correct
16 Correct 1 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 1 ms 332 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 2 ms 588 KB Output is correct
29 Correct 1 ms 304 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 2 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 2 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 1 ms 204 KB Output is correct
39 Correct 1 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 1 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 1 ms 204 KB Output is correct
46 Correct 1 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 1 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 50 ms 15428 KB Output is correct
2 Correct 48 ms 15280 KB Output is correct
3 Correct 39 ms 10176 KB Output is correct
4 Correct 6 ms 2472 KB Output is correct
5 Correct 5 ms 1688 KB Output is correct
6 Correct 13 ms 3788 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 23 ms 6220 KB Output is correct
9 Correct 47 ms 8220 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 59 ms 10728 KB Output is correct
12 Correct 72 ms 13236 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 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 1 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 1 ms 204 KB Output is correct
29 Correct 1 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 0 ms 204 KB Output is correct
39 Correct 48 ms 15360 KB Output is correct
40 Correct 48 ms 15376 KB Output is correct
41 Correct 29 ms 10184 KB Output is correct
42 Correct 6 ms 2508 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 1 ms 204 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 1 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 1 ms 204 KB Output is correct
52 Correct 0 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 78 ms 11936 KB Output is correct
58 Correct 90 ms 11648 KB Output is correct
59 Correct 91 ms 11580 KB Output is correct
60 Correct 131 ms 11356 KB Output is correct
61 Correct 74 ms 11456 KB Output is correct
62 Correct 70 ms 11212 KB Output is correct
63 Correct 92 ms 11152 KB Output is correct
64 Correct 73 ms 11176 KB Output is correct
65 Correct 70 ms 11168 KB Output is correct
66 Correct 65 ms 11200 KB Output is correct
67 Correct 86 ms 11700 KB Output is correct
68 Correct 82 ms 11668 KB Output is correct
69 Correct 97 ms 11308 KB Output is correct
70 Correct 76 ms 11332 KB Output is correct
71 Correct 0 ms 204 KB Output is correct
72 Correct 2 ms 588 KB Output is correct
73 Correct 2 ms 588 KB Output is correct
74 Correct 2 ms 588 KB Output is correct
75 Correct 2 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 3 ms 588 KB Output is correct
79 Correct 3 ms 588 KB Output is correct
80 Correct 79 ms 11640 KB Output is correct
81 Correct 76 ms 11568 KB Output is correct
82 Correct 70 ms 11436 KB Output is correct
83 Correct 69 ms 11420 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 1 ms 588 KB Output is correct
89 Correct 2 ms 588 KB Output is correct
90 Correct 2 ms 588 KB Output is correct
91 Correct 2 ms 588 KB Output is correct
92 Correct 2 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 0 ms 204 KB Output is correct
101 Correct 0 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 12 ms 3788 KB Output is correct
106 Correct 1 ms 332 KB Output is correct
107 Correct 23 ms 6092 KB Output is correct
108 Correct 31 ms 8260 KB Output is correct
109 Correct 1 ms 332 KB Output is correct
110 Correct 58 ms 10824 KB Output is correct
111 Correct 62 ms 13228 KB Output is correct
112 Correct 1 ms 332 KB Output is correct
113 Correct 93 ms 17284 KB Output is correct
114 Correct 54 ms 7444 KB Output is correct
115 Correct 58 ms 7396 KB Output is correct
116 Correct 81 ms 7416 KB Output is correct
117 Correct 62 ms 7460 KB Output is correct
118 Correct 54 ms 7412 KB Output is correct
119 Correct 67 ms 8796 KB Output is correct
120 Correct 61 ms 7704 KB Output is correct
121 Correct 54 ms 7324 KB Output is correct
122 Correct 77 ms 7300 KB Output is correct
123 Correct 58 ms 7616 KB Output is correct
124 Correct 0 ms 204 KB Output is correct
125 Correct 67 ms 6328 KB Output is correct
126 Correct 66 ms 6420 KB Output is correct
127 Correct 64 ms 6328 KB Output is correct
128 Correct 63 ms 6352 KB Output is correct
129 Correct 66 ms 6416 KB Output is correct
130 Correct 63 ms 6392 KB Output is correct
131 Correct 64 ms 6372 KB Output is correct
132 Correct 71 ms 6356 KB Output is correct
133 Incorrect 0 ms 204 KB Output isn't correct
134 Halted 0 ms 0 KB -