Submission #492182

# Submission time Handle Problem Language Result Execution time Memory
492182 2021-12-05T20:28:55 Z aci Dreaming (IOI13_dreaming) C++14
47 / 100
109 ms 18340 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
#define INF 1000000000
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);
    long long 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 48 ms 15424 KB Output is correct
2 Correct 47 ms 15296 KB Output is correct
3 Correct 30 ms 10176 KB Output is correct
4 Correct 6 ms 2548 KB Output is correct
5 Correct 5 ms 1692 KB Output is correct
6 Correct 11 ms 3884 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 22 ms 6628 KB Output is correct
9 Correct 34 ms 8960 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 52 ms 11792 KB Output is correct
12 Correct 65 ms 14200 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 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 1 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 1 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 1 ms 204 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 1 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 48 ms 15424 KB Output is correct
2 Correct 47 ms 15296 KB Output is correct
3 Correct 30 ms 10176 KB Output is correct
4 Correct 6 ms 2548 KB Output is correct
5 Correct 5 ms 1692 KB Output is correct
6 Correct 11 ms 3884 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 22 ms 6628 KB Output is correct
9 Correct 34 ms 8960 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 52 ms 11792 KB Output is correct
12 Correct 65 ms 14200 KB Output is correct
13 Correct 1 ms 460 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 1 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 1 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 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 1 ms 204 KB Output is correct
35 Correct 1 ms 300 KB Output is correct
36 Correct 1 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 16452 KB Output is correct
40 Correct 48 ms 16308 KB Output is correct
41 Correct 30 ms 11144 KB Output is correct
42 Correct 6 ms 2764 KB Output is correct
43 Correct 0 ms 216 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 0 ms 204 KB Output is correct
46 Correct 0 ms 296 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 0 ms 204 KB Output is correct
53 Correct 0 ms 204 KB Output is correct
54 Correct 1 ms 204 KB Output is correct
55 Correct 1 ms 204 KB Output is correct
56 Correct 0 ms 204 KB Output is correct
57 Correct 89 ms 12956 KB Output is correct
58 Correct 103 ms 12672 KB Output is correct
59 Correct 109 ms 12608 KB Output is correct
60 Correct 88 ms 12408 KB Output is correct
61 Correct 76 ms 12460 KB Output is correct
62 Correct 70 ms 12112 KB Output is correct
63 Correct 72 ms 12108 KB Output is correct
64 Correct 66 ms 12148 KB Output is correct
65 Correct 68 ms 12224 KB Output is correct
66 Correct 68 ms 12164 KB Output is correct
67 Correct 82 ms 12740 KB Output is correct
68 Correct 75 ms 12612 KB Output is correct
69 Correct 76 ms 12380 KB Output is correct
70 Correct 75 ms 12416 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 676 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 12544 KB Output is correct
81 Correct 72 ms 12608 KB Output is correct
82 Correct 68 ms 12460 KB Output is correct
83 Correct 72 ms 12376 KB Output is correct
84 Correct 1 ms 588 KB Output is correct
85 Correct 1 ms 460 KB Output is correct
86 Correct 1 ms 588 KB Output is correct
87 Correct 2 ms 588 KB Output is correct
88 Correct 1 ms 588 KB Output is correct
89 Correct 1 ms 588 KB Output is correct
90 Correct 1 ms 588 KB Output is correct
91 Correct 2 ms 568 KB Output is correct
92 Correct 2 ms 588 KB Output is correct
93 Correct 2 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 1 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 304 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 1868 KB Output is correct
105 Correct 11 ms 4172 KB Output is correct
106 Correct 1 ms 332 KB Output is correct
107 Correct 22 ms 6736 KB Output is correct
108 Correct 33 ms 8992 KB Output is correct
109 Correct 1 ms 336 KB Output is correct
110 Correct 50 ms 11856 KB Output is correct
111 Correct 68 ms 14276 KB Output is correct
112 Correct 1 ms 460 KB Output is correct
113 Correct 96 ms 18340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 7444 KB Output is correct
2 Correct 55 ms 7400 KB Output is correct
3 Correct 58 ms 7440 KB Output is correct
4 Correct 57 ms 7396 KB Output is correct
5 Correct 54 ms 7368 KB Output is correct
6 Correct 64 ms 8896 KB Output is correct
7 Correct 62 ms 7748 KB Output is correct
8 Correct 53 ms 7348 KB Output is correct
9 Correct 54 ms 7300 KB Output is correct
10 Correct 60 ms 7608 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 65 ms 6400 KB Output is correct
13 Correct 64 ms 6456 KB Output is correct
14 Correct 64 ms 6412 KB Output is correct
15 Correct 65 ms 6368 KB Output is correct
16 Correct 63 ms 6328 KB Output is correct
17 Correct 63 ms 6344 KB Output is correct
18 Correct 63 ms 6432 KB Output is correct
19 Correct 63 ms 6396 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 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 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 1 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 1 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 1 ms 204 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 1 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 308 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 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 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 0 ms 300 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 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 1 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 208 KB Output is correct
51 Correct 1 ms 204 KB Output is correct
52 Incorrect 0 ms 300 KB Output isn't correct
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 15424 KB Output is correct
2 Correct 47 ms 15296 KB Output is correct
3 Correct 30 ms 10176 KB Output is correct
4 Correct 6 ms 2548 KB Output is correct
5 Correct 5 ms 1692 KB Output is correct
6 Correct 11 ms 3884 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 22 ms 6628 KB Output is correct
9 Correct 34 ms 8960 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 52 ms 11792 KB Output is correct
12 Correct 65 ms 14200 KB Output is correct
13 Correct 1 ms 460 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 1 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 1 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 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 1 ms 204 KB Output is correct
35 Correct 1 ms 300 KB Output is correct
36 Correct 1 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 16452 KB Output is correct
40 Correct 48 ms 16308 KB Output is correct
41 Correct 30 ms 11144 KB Output is correct
42 Correct 6 ms 2764 KB Output is correct
43 Correct 0 ms 216 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 0 ms 204 KB Output is correct
46 Correct 0 ms 296 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 0 ms 204 KB Output is correct
53 Correct 0 ms 204 KB Output is correct
54 Correct 1 ms 204 KB Output is correct
55 Correct 1 ms 204 KB Output is correct
56 Correct 0 ms 204 KB Output is correct
57 Correct 89 ms 12956 KB Output is correct
58 Correct 103 ms 12672 KB Output is correct
59 Correct 109 ms 12608 KB Output is correct
60 Correct 88 ms 12408 KB Output is correct
61 Correct 76 ms 12460 KB Output is correct
62 Correct 70 ms 12112 KB Output is correct
63 Correct 72 ms 12108 KB Output is correct
64 Correct 66 ms 12148 KB Output is correct
65 Correct 68 ms 12224 KB Output is correct
66 Correct 68 ms 12164 KB Output is correct
67 Correct 82 ms 12740 KB Output is correct
68 Correct 75 ms 12612 KB Output is correct
69 Correct 76 ms 12380 KB Output is correct
70 Correct 75 ms 12416 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 676 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 12544 KB Output is correct
81 Correct 72 ms 12608 KB Output is correct
82 Correct 68 ms 12460 KB Output is correct
83 Correct 72 ms 12376 KB Output is correct
84 Correct 1 ms 588 KB Output is correct
85 Correct 1 ms 460 KB Output is correct
86 Correct 1 ms 588 KB Output is correct
87 Correct 2 ms 588 KB Output is correct
88 Correct 1 ms 588 KB Output is correct
89 Correct 1 ms 588 KB Output is correct
90 Correct 1 ms 588 KB Output is correct
91 Correct 2 ms 568 KB Output is correct
92 Correct 2 ms 588 KB Output is correct
93 Correct 2 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 1 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 304 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 1868 KB Output is correct
105 Correct 11 ms 4172 KB Output is correct
106 Correct 1 ms 332 KB Output is correct
107 Correct 22 ms 6736 KB Output is correct
108 Correct 33 ms 8992 KB Output is correct
109 Correct 1 ms 336 KB Output is correct
110 Correct 50 ms 11856 KB Output is correct
111 Correct 68 ms 14276 KB Output is correct
112 Correct 1 ms 460 KB Output is correct
113 Correct 96 ms 18340 KB Output is correct
114 Correct 55 ms 7444 KB Output is correct
115 Correct 55 ms 7400 KB Output is correct
116 Correct 58 ms 7440 KB Output is correct
117 Correct 57 ms 7396 KB Output is correct
118 Correct 54 ms 7368 KB Output is correct
119 Correct 64 ms 8896 KB Output is correct
120 Correct 62 ms 7748 KB Output is correct
121 Correct 53 ms 7348 KB Output is correct
122 Correct 54 ms 7300 KB Output is correct
123 Correct 60 ms 7608 KB Output is correct
124 Correct 0 ms 204 KB Output is correct
125 Correct 65 ms 6400 KB Output is correct
126 Correct 64 ms 6456 KB Output is correct
127 Correct 64 ms 6412 KB Output is correct
128 Correct 65 ms 6368 KB Output is correct
129 Correct 63 ms 6328 KB Output is correct
130 Correct 63 ms 6344 KB Output is correct
131 Correct 63 ms 6432 KB Output is correct
132 Correct 63 ms 6396 KB Output is correct
133 Incorrect 0 ms 204 KB Output isn't correct
134 Halted 0 ms 0 KB -