Submission #920112

# Submission time Handle Problem Language Result Execution time Memory
920112 2024-02-02T04:48:27 Z Juanchoki Dreaming (IOI13_dreaming) C++14
47 / 100
537 ms 32336 KB
#include"dreaming.h"
#include <bits/stdc++.h>
using namespace std;
struct edge
{
    int u, w;
};
struct tpos
{
    int nodo, dist, padre;
};
int maxn;
const int MAXN = 2e5 + 4;
int Visi[MAXN];
vector<vector<edge>> adj;
struct Component 
{
    int first;
    int second;
};
bool operator < (const Component& a, const Component& b) { return a.second < b.second; }
Component bfs (int nodo)
{
        Component ret;
        ret.second = -1;
        queue<tpos> q; 
        q.push({nodo, 0, -1});
        tpos temp_tpos;
        vector<bool> visi(maxn);
        while (!q.empty())
        {
            temp_tpos = q.front(); q.pop();
            visi[temp_tpos.nodo] = 1;
            Visi[temp_tpos.nodo] = 1;
            //cout << "    " << temp_tpos.nodo <<  " " << temp_tpos.dist << "\n";
            for (edge e: adj[temp_tpos.nodo])
            {
           //     cout << temp_tpos.nodo << " vecinos: " << e.u << '\n';
                if (visi[e.u]) continue;
                q.push({e.u, temp_tpos.dist+e.w, temp_tpos.nodo}); 
            }
            if (temp_tpos.dist > ret.second)
            {
                ret.second = temp_tpos.dist;
                ret.first = temp_tpos.nodo;
            }
        }
    //cout << '\n';
    return ret;
}
tpos Diametro (int pos)
{
    int ve = bfs(pos).first;
    tpos ttpos;
    ttpos.nodo = ve;
    Component par = bfs(ve);
    ttpos.dist = par.first;
    ttpos.padre = par.second;
    return ttpos;
}
 
void DFS(int nodo, int dist, map<int, bool> &visit, map<int, int> &ret)
{
    visit[nodo] = 1;
    ret[nodo] = dist;
    for (edge &e: adj[nodo])
        if (visit[e.u]) continue;
        else DFS(e.u, dist + e.w, visit, ret);
}
 
int distanciaxdd (int nodo, map<int, bool> &visit, map<int, int> &a, map<int, int> &b)
{
    visit[nodo] = 1;
    int mini = max(a[nodo], b[nodo]);
    for (edge &e: adj[nodo])
        if (visit[e.u]) continue;
        else mini = min (mini, distanciaxdd(e.u, visit, a, b));
    return mini;
}
 
int travelTime(int N, int M, int L, int A[], int B[], int T[]) 
{
    maxn = N;
    adj.resize(N);
    edge temp_edge;
    for (int i = 0; i < M; i++)
    {
        temp_edge.u = B[i];
        temp_edge.w = T[i];
        adj[A[i]].push_back(temp_edge);
        temp_edge.u = A[i];
        adj[B[i]].push_back(temp_edge);
    }
    queue<Component> pq;
    Component par;
 
    for (int i = 0; i < N; i++)
    {
        if (Visi[i]) continue;
        tpos ttpos = Diametro(i);
        par.first = ttpos.padre;
        map<int, int> uno, dos;
        map<int, bool> visit;
        DFS(ttpos.nodo, 0, visit, uno);
        visit.clear();
        DFS(ttpos.dist, 0, visit, dos);
        visit.clear();
        par.second = distanciaxdd(i, visit, uno, dos);
       // cout << i << " " << par.first << " " << par.second << '\n';
        pq.push(par);
    }
        
    while (pq.size() > 1)
    {
        Component a1 = pq.front(); pq.pop();
        Component a2 = pq.front(); pq.pop();
     //   cout << a1.first << ' ' << a2.first << '\n';
        Component temporal;
        temporal.first = max(a1.first, max(a2.first, a1.second + a2.second + L));
        temporal.second = min (max (a1.second + L, a2.second), max(a2.second + L, a1.second));
        pq.push(temporal);
    }
 
    return pq.front().first;
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 385 ms 28240 KB Output is correct
2 Correct 386 ms 28212 KB Output is correct
3 Correct 192 ms 18512 KB Output is correct
4 Correct 29 ms 4440 KB Output is correct
5 Correct 21 ms 2136 KB Output is correct
6 Correct 62 ms 6480 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 99 ms 8792 KB Output is correct
9 Correct 145 ms 13648 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 221 ms 16464 KB Output is correct
12 Correct 330 ms 22424 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 385 ms 28240 KB Output is correct
2 Correct 386 ms 28212 KB Output is correct
3 Correct 192 ms 18512 KB Output is correct
4 Correct 29 ms 4440 KB Output is correct
5 Correct 21 ms 2136 KB Output is correct
6 Correct 62 ms 6480 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 99 ms 8792 KB Output is correct
9 Correct 145 ms 13648 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 221 ms 16464 KB Output is correct
12 Correct 330 ms 22424 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 430 ms 28176 KB Output is correct
40 Correct 432 ms 27984 KB Output is correct
41 Correct 199 ms 18512 KB Output is correct
42 Correct 29 ms 4440 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 1 ms 600 KB Output is correct
46 Correct 0 ms 600 KB Output is correct
47 Correct 1 ms 344 KB Output is correct
48 Correct 1 ms 600 KB Output is correct
49 Correct 1 ms 344 KB Output is correct
50 Correct 1 ms 344 KB Output is correct
51 Correct 0 ms 344 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Correct 1 ms 344 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 386 ms 21332 KB Output is correct
58 Correct 290 ms 15952 KB Output is correct
59 Correct 397 ms 20304 KB Output is correct
60 Correct 319 ms 15184 KB Output is correct
61 Correct 399 ms 20260 KB Output is correct
62 Correct 336 ms 17264 KB Output is correct
63 Correct 449 ms 22096 KB Output is correct
64 Correct 447 ms 21908 KB Output is correct
65 Correct 470 ms 22024 KB Output is correct
66 Correct 441 ms 22096 KB Output is correct
67 Correct 415 ms 20748 KB Output is correct
68 Correct 397 ms 20584 KB Output is correct
69 Correct 317 ms 16464 KB Output is correct
70 Correct 305 ms 16432 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 5 ms 856 KB Output is correct
73 Correct 5 ms 860 KB Output is correct
74 Correct 5 ms 856 KB Output is correct
75 Correct 5 ms 856 KB Output is correct
76 Correct 7 ms 1060 KB Output is correct
77 Correct 6 ms 860 KB Output is correct
78 Correct 5 ms 856 KB Output is correct
79 Correct 5 ms 856 KB Output is correct
80 Correct 346 ms 18024 KB Output is correct
81 Correct 373 ms 18000 KB Output is correct
82 Correct 385 ms 20304 KB Output is correct
83 Correct 423 ms 21808 KB Output is correct
84 Correct 4 ms 600 KB Output is correct
85 Correct 4 ms 856 KB Output is correct
86 Correct 1 ms 756 KB Output is correct
87 Correct 4 ms 600 KB Output is correct
88 Correct 5 ms 600 KB Output is correct
89 Correct 4 ms 600 KB Output is correct
90 Correct 5 ms 600 KB Output is correct
91 Correct 5 ms 856 KB Output is correct
92 Correct 5 ms 856 KB Output is correct
93 Correct 5 ms 856 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 1 ms 344 KB Output is correct
98 Correct 1 ms 344 KB Output is correct
99 Correct 0 ms 348 KB Output is correct
100 Correct 1 ms 348 KB Output is correct
101 Correct 1 ms 344 KB Output is correct
102 Correct 1 ms 344 KB Output is correct
103 Correct 1 ms 344 KB Output is correct
104 Correct 19 ms 2136 KB Output is correct
105 Correct 49 ms 6384 KB Output is correct
106 Correct 1 ms 348 KB Output is correct
107 Correct 98 ms 8784 KB Output is correct
108 Correct 147 ms 13648 KB Output is correct
109 Correct 2 ms 600 KB Output is correct
110 Correct 251 ms 16464 KB Output is correct
111 Correct 367 ms 22360 KB Output is correct
112 Correct 2 ms 600 KB Output is correct
113 Correct 537 ms 32336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 5712 KB Output is correct
2 Incorrect 51 ms 5976 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 3 ms 684 KB Output is correct
29 Incorrect 1 ms 344 KB Output isn't correct
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 385 ms 28240 KB Output is correct
2 Correct 386 ms 28212 KB Output is correct
3 Correct 192 ms 18512 KB Output is correct
4 Correct 29 ms 4440 KB Output is correct
5 Correct 21 ms 2136 KB Output is correct
6 Correct 62 ms 6480 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 99 ms 8792 KB Output is correct
9 Correct 145 ms 13648 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 221 ms 16464 KB Output is correct
12 Correct 330 ms 22424 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 430 ms 28176 KB Output is correct
40 Correct 432 ms 27984 KB Output is correct
41 Correct 199 ms 18512 KB Output is correct
42 Correct 29 ms 4440 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 1 ms 600 KB Output is correct
46 Correct 0 ms 600 KB Output is correct
47 Correct 1 ms 344 KB Output is correct
48 Correct 1 ms 600 KB Output is correct
49 Correct 1 ms 344 KB Output is correct
50 Correct 1 ms 344 KB Output is correct
51 Correct 0 ms 344 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Correct 1 ms 344 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 386 ms 21332 KB Output is correct
58 Correct 290 ms 15952 KB Output is correct
59 Correct 397 ms 20304 KB Output is correct
60 Correct 319 ms 15184 KB Output is correct
61 Correct 399 ms 20260 KB Output is correct
62 Correct 336 ms 17264 KB Output is correct
63 Correct 449 ms 22096 KB Output is correct
64 Correct 447 ms 21908 KB Output is correct
65 Correct 470 ms 22024 KB Output is correct
66 Correct 441 ms 22096 KB Output is correct
67 Correct 415 ms 20748 KB Output is correct
68 Correct 397 ms 20584 KB Output is correct
69 Correct 317 ms 16464 KB Output is correct
70 Correct 305 ms 16432 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 5 ms 856 KB Output is correct
73 Correct 5 ms 860 KB Output is correct
74 Correct 5 ms 856 KB Output is correct
75 Correct 5 ms 856 KB Output is correct
76 Correct 7 ms 1060 KB Output is correct
77 Correct 6 ms 860 KB Output is correct
78 Correct 5 ms 856 KB Output is correct
79 Correct 5 ms 856 KB Output is correct
80 Correct 346 ms 18024 KB Output is correct
81 Correct 373 ms 18000 KB Output is correct
82 Correct 385 ms 20304 KB Output is correct
83 Correct 423 ms 21808 KB Output is correct
84 Correct 4 ms 600 KB Output is correct
85 Correct 4 ms 856 KB Output is correct
86 Correct 1 ms 756 KB Output is correct
87 Correct 4 ms 600 KB Output is correct
88 Correct 5 ms 600 KB Output is correct
89 Correct 4 ms 600 KB Output is correct
90 Correct 5 ms 600 KB Output is correct
91 Correct 5 ms 856 KB Output is correct
92 Correct 5 ms 856 KB Output is correct
93 Correct 5 ms 856 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 1 ms 344 KB Output is correct
98 Correct 1 ms 344 KB Output is correct
99 Correct 0 ms 348 KB Output is correct
100 Correct 1 ms 348 KB Output is correct
101 Correct 1 ms 344 KB Output is correct
102 Correct 1 ms 344 KB Output is correct
103 Correct 1 ms 344 KB Output is correct
104 Correct 19 ms 2136 KB Output is correct
105 Correct 49 ms 6384 KB Output is correct
106 Correct 1 ms 348 KB Output is correct
107 Correct 98 ms 8784 KB Output is correct
108 Correct 147 ms 13648 KB Output is correct
109 Correct 2 ms 600 KB Output is correct
110 Correct 251 ms 16464 KB Output is correct
111 Correct 367 ms 22360 KB Output is correct
112 Correct 2 ms 600 KB Output is correct
113 Correct 537 ms 32336 KB Output is correct
114 Correct 51 ms 5712 KB Output is correct
115 Incorrect 51 ms 5976 KB Output isn't correct
116 Halted 0 ms 0 KB -