Submission #430651

# Submission time Handle Problem Language Result Execution time Memory
430651 2021-06-16T18:02:24 Z muhammad_hokimiyon Dreaming (IOI13_dreaming) C++14
40 / 100
1000 ms 17516 KB
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;

const int maxN = 1e5 + 7;

int val,ve;
bool used[maxN];
vector<pair<int, int>> v[maxN];

void dfs(int x, int p, int sum)
{
        used[x] = true;
        if(sum >= val){
                val = sum;
                ve = x;
        }
        for(auto y : v[x]){
                if(y.first != p){
                        dfs(y.first, x, sum + y.second);
                }
        }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
        for(int i = 0; i < M; i++){
                v[A[i]].push_back({B[i], T[i]});
                v[B[i]].push_back({A[i], T[i]});
        }
        vector<int> p(N, -1);
        vector<int> d(N, 1e9);
        vector<pair<int, int>> X;
        for(int i = 0; i < N; i++){
                if(!used[i]){
                        val = ve = 0;
                        dfs(i, i, 0);
                        int r1 = ve;
                        val = ve = 0;
                        dfs(r1, r1, 0);
                        int r2 = ve;
                        queue<int> q;
                        q.push(r1);
                        d[r1] = 0;
                        while(!q.empty()){
                                int x = q.front();
                                q.pop();
                                for(auto y : v[x]){
                                        if(d[y.first] == 1e9){
                                                d[y.first] = d[x] + 1;
                                                p[y.first] = x;
                                                q.push(y.first);
                                        }
                                }
                        }
                        vector<int> pa;
                        while(r2 != r1){
                                pa.push_back(r2);
                                r2 = p[r2];
                        }
                        pa.push_back(r1);
                        int v1 = 0;
                        int res = 1e9;
                        for(int j = max(0, (int)pa.size() / 2 - 10); j < min((int)pa.size(), (int)pa.size() / 2 + 10); j++){
                                int st = pa[j];
                                queue<int> q;
                                q.push(st);
                                map<int, int> d;
                                int mx = 0;
                                d[st] = 0;
                                while(!q.empty()){
                                        int x = q.front();
                                        q.pop();
                                        for(auto y : v[x]){
                                                if(d.find(y.first) == d.end()){
                                                        d[y.first] = d[x] + y.second;
                                                        q.push(y.first);
                                                        mx = max(mx, d[x] + y.second);
                                                }
                                        }
                                }
                                if(mx < res){
                                        res = mx;
                                        v1 = st;
                                }
                        }
                        X.push_back({res, v1});
                }
        }
        sort(X.rbegin(), X.rend());
        for(int i = 1; i < (int)X.size(); i++){
                v[X[0].second].push_back({X[i].second, L});
                v[X[i].second].push_back({X[0].second, L});
        }
        val = ve = 0;
        dfs(0, 0, 0);
        val = 0;
        dfs(ve, ve, 0);
        return val;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1098 ms 17516 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 3 ms 2636 KB Output is correct
4 Correct 3 ms 2636 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 3 ms 2656 KB Output is correct
7 Correct 3 ms 2636 KB Output is correct
8 Correct 3 ms 2636 KB Output is correct
9 Correct 3 ms 2636 KB Output is correct
10 Correct 3 ms 2636 KB Output is correct
11 Correct 3 ms 2636 KB Output is correct
12 Correct 2 ms 2660 KB Output is correct
13 Correct 3 ms 2636 KB Output is correct
14 Correct 3 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2656 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 3 ms 2636 KB Output is correct
19 Correct 3 ms 2636 KB Output is correct
20 Correct 3 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 3 ms 2652 KB Output is correct
23 Correct 3 ms 2664 KB Output is correct
24 Correct 3 ms 2664 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1098 ms 17516 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 66 ms 8072 KB Output is correct
2 Correct 76 ms 8140 KB Output is correct
3 Correct 72 ms 8080 KB Output is correct
4 Correct 72 ms 8176 KB Output is correct
5 Correct 68 ms 8120 KB Output is correct
6 Correct 70 ms 8992 KB Output is correct
7 Correct 67 ms 8392 KB Output is correct
8 Correct 71 ms 8076 KB Output is correct
9 Correct 92 ms 8144 KB Output is correct
10 Correct 96 ms 8268 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 41 ms 8172 KB Output is correct
13 Correct 40 ms 8200 KB Output is correct
14 Correct 44 ms 8120 KB Output is correct
15 Correct 53 ms 8120 KB Output is correct
16 Correct 52 ms 8144 KB Output is correct
17 Correct 41 ms 8208 KB Output is correct
18 Correct 41 ms 8200 KB Output is correct
19 Correct 41 ms 8168 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 3 ms 2636 KB Output is correct
22 Correct 3 ms 2764 KB Output is correct
23 Correct 42 ms 8112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 3 ms 2636 KB Output is correct
4 Correct 3 ms 2636 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 3 ms 2656 KB Output is correct
7 Correct 3 ms 2636 KB Output is correct
8 Correct 3 ms 2636 KB Output is correct
9 Correct 3 ms 2636 KB Output is correct
10 Correct 3 ms 2636 KB Output is correct
11 Correct 3 ms 2636 KB Output is correct
12 Correct 2 ms 2660 KB Output is correct
13 Correct 3 ms 2636 KB Output is correct
14 Correct 3 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2656 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 3 ms 2636 KB Output is correct
19 Correct 3 ms 2636 KB Output is correct
20 Correct 3 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 3 ms 2652 KB Output is correct
23 Correct 3 ms 2664 KB Output is correct
24 Correct 3 ms 2664 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 3 ms 2636 KB Output is correct
27 Correct 6 ms 2764 KB Output is correct
28 Correct 7 ms 2764 KB Output is correct
29 Correct 4 ms 2636 KB Output is correct
30 Correct 4 ms 2764 KB Output is correct
31 Correct 6 ms 2764 KB Output is correct
32 Correct 3 ms 2636 KB Output is correct
33 Correct 5 ms 2800 KB Output is correct
34 Correct 6 ms 2764 KB Output is correct
35 Correct 2 ms 2636 KB Output is correct
36 Correct 3 ms 2660 KB Output is correct
37 Correct 3 ms 2636 KB Output is correct
38 Correct 3 ms 2660 KB Output is correct
39 Correct 3 ms 2636 KB Output is correct
40 Correct 3 ms 2660 KB Output is correct
41 Correct 2 ms 2636 KB Output is correct
42 Correct 3 ms 2636 KB Output is correct
43 Correct 3 ms 2636 KB Output is correct
44 Correct 3 ms 2652 KB Output is correct
45 Correct 3 ms 2656 KB Output is correct
46 Correct 3 ms 2636 KB Output is correct
47 Correct 3 ms 2636 KB Output is correct
48 Correct 3 ms 2636 KB Output is correct
49 Correct 3 ms 2636 KB Output is correct
50 Correct 3 ms 2664 KB Output is correct
51 Correct 3 ms 2636 KB Output is correct
52 Correct 2 ms 2636 KB Output is correct
53 Correct 2 ms 2636 KB Output is correct
54 Correct 33 ms 3148 KB Output is correct
55 Correct 33 ms 3132 KB Output is correct
56 Correct 6 ms 2764 KB Output is correct
57 Correct 5 ms 2764 KB Output is correct
58 Correct 32 ms 2892 KB Output is correct
59 Correct 34 ms 2892 KB Output is correct
60 Correct 4 ms 2764 KB Output is correct
61 Correct 4 ms 2764 KB Output is correct
62 Correct 33 ms 3012 KB Output is correct
63 Correct 31 ms 2892 KB Output is correct
64 Correct 4 ms 2784 KB Output is correct
65 Correct 5 ms 2820 KB Output is correct
66 Correct 33 ms 2892 KB Output is correct
67 Correct 39 ms 2924 KB Output is correct
68 Correct 5 ms 2764 KB Output is correct
69 Correct 8 ms 2840 KB Output is correct
70 Correct 5 ms 2764 KB Output is correct
71 Correct 5 ms 2764 KB Output is correct
72 Correct 33 ms 2892 KB Output is correct
73 Correct 35 ms 3000 KB Output is correct
74 Correct 13 ms 2764 KB Output is correct
75 Correct 14 ms 2800 KB Output is correct
76 Correct 32 ms 2952 KB Output is correct
77 Correct 33 ms 2892 KB Output is correct
78 Correct 4 ms 2764 KB Output is correct
79 Correct 4 ms 2764 KB Output is correct
80 Correct 3 ms 2764 KB Output is correct
81 Correct 3 ms 2792 KB Output is correct
82 Correct 8 ms 2868 KB Output is correct
83 Correct 8 ms 2764 KB Output is correct
84 Correct 10 ms 2796 KB Output is correct
85 Correct 4 ms 2792 KB Output is correct
86 Correct 19 ms 2892 KB Output is correct
87 Correct 30 ms 2892 KB Output is correct
88 Correct 5 ms 2764 KB Output is correct
89 Correct 5 ms 2800 KB Output is correct
90 Correct 4 ms 2800 KB Output is correct
91 Correct 4 ms 2764 KB Output is correct
92 Correct 10 ms 2896 KB Output is correct
93 Correct 12 ms 2892 KB Output is correct
94 Correct 18 ms 2764 KB Output is correct
95 Correct 28 ms 2908 KB Output is correct
96 Correct 19 ms 2908 KB Output is correct
97 Correct 19 ms 2900 KB Output is correct
98 Correct 27 ms 2912 KB Output is correct
99 Correct 34 ms 2984 KB Output is correct
100 Correct 29 ms 2952 KB Output is correct
101 Correct 24 ms 2892 KB Output is correct
102 Correct 2 ms 2636 KB Output is correct
103 Correct 2 ms 2636 KB Output is correct
104 Correct 3 ms 2664 KB Output is correct
105 Correct 2 ms 2636 KB Output is correct
106 Correct 3 ms 2636 KB Output is correct
107 Correct 2 ms 2636 KB Output is correct
108 Correct 3 ms 2636 KB Output is correct
109 Correct 3 ms 2636 KB Output is correct
110 Correct 3 ms 2636 KB Output is correct
111 Correct 2 ms 2636 KB Output is correct
112 Correct 5 ms 2636 KB Output is correct
113 Correct 8 ms 2764 KB Output is correct
114 Correct 10 ms 2784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1098 ms 17516 KB Time limit exceeded
2 Halted 0 ms 0 KB -