Submission #167389

# Submission time Handle Problem Language Result Execution time Memory
167389 2019-12-08T00:04:42 Z DavidDamian Dreaming (IOI13_dreaming) C++11
47 / 100
105 ms 12644 KB
#include "dreaming.h"
#include<queue>
#include<vector>
#include<iostream>
using namespace std;
///Diameter of a tree
///Determine the minimum longest path selecting optimal connections
struct edge
{
    int from,to;
    int w;
};
int color[100005];
int d[2][100005]; //Distance from node 1 and node 2
queue<int> Q;
vector<edge> adjList[100005];
int bfs(int s,int node,int c) ///Returns the farest node of s
{
    color[s]=c;
    d[node][s]=0;
    Q.push(s);
    int maximum=0;
    int max_Node=s;
    while(Q.size()){
        int u=Q.front();Q.pop();
        for(edge e: adjList[u]){
            int v=e.to;
            if(color[v]!=c){
                color[v]=c;
                d[node][v]=d[node][u]+e.w;
                if(d[node][v]>maximum){
                    maximum=d[node][v];
                    max_Node=v;
                }
                Q.push(v);
            }
        }
    }
    return max_Node;
}
int getMinimum_FarestDistance(int s,int c) ///Returns the minimum longest distance in a tree
{
    color[s]=c;
    Q.push(s);
    int minimum=1000000000;
    while(Q.size()){
        int u=Q.front();Q.pop();
        if(max(d[0][u],d[1][u]) < minimum){
            minimum=max(d[0][u],d[1][u]);
        }
        for(edge e: adjList[u]){
            int v=e.to;
            if(color[v]!=c){
                color[v]=c;
                Q.push(v);
            }
        }
    }
    return minimum;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for(int i=0;i<M;i++){
        edge e={A[i],B[i],T[i]};
        adjList[ A[i] ].push_back(e);
        swap(e.from,e.to);
        adjList[ B[i] ].push_back(e);
    }
    int c=1;
    int best[5];
    int j=0;
    int answer=0;
    for(int i=0;i<N;i++){
        if(color[i]!=0) continue;
        int u=bfs(i,0,c++); //Gets the farest node of i
        int v=bfs(u,1,c++); //Gets the farest node of u
        //u and v are the farest nodes between themselves in the tree
        answer=max(answer,d[1][v]);
        bfs(v,0,c++);
        best[j++]=getMinimum_FarestDistance(i,c);
    }
    int NewPath=best[0]+best[1]+L;
    answer=max(answer,NewPath);
    return answer;
}
# Verdict Execution time Memory Grader output
1 Correct 73 ms 8952 KB Output is correct
2 Correct 68 ms 8952 KB Output is correct
3 Correct 46 ms 6904 KB Output is correct
4 Correct 13 ms 3676 KB Output is correct
5 Correct 12 ms 3320 KB Output is correct
6 Correct 21 ms 4216 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 38 ms 5496 KB Output is correct
9 Correct 45 ms 6136 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 66 ms 7680 KB Output is correct
12 Correct 73 ms 8184 KB Output is correct
13 Correct 4 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 8952 KB Output is correct
2 Correct 68 ms 8952 KB Output is correct
3 Correct 46 ms 6904 KB Output is correct
4 Correct 13 ms 3676 KB Output is correct
5 Correct 12 ms 3320 KB Output is correct
6 Correct 21 ms 4216 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 38 ms 5496 KB Output is correct
9 Correct 45 ms 6136 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 66 ms 7680 KB Output is correct
12 Correct 73 ms 8184 KB Output is correct
13 Correct 4 ms 2808 KB Output is correct
14 Correct 4 ms 2680 KB Output is correct
15 Correct 4 ms 2680 KB Output is correct
16 Correct 4 ms 2680 KB Output is correct
17 Correct 4 ms 2680 KB Output is correct
18 Correct 4 ms 2680 KB Output is correct
19 Correct 4 ms 2680 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 4 ms 2680 KB Output is correct
22 Correct 4 ms 2680 KB Output is correct
23 Correct 4 ms 2680 KB Output is correct
24 Correct 4 ms 2680 KB Output is correct
25 Correct 4 ms 2680 KB Output is correct
26 Correct 4 ms 2680 KB Output is correct
27 Correct 4 ms 2680 KB Output is correct
28 Correct 4 ms 2680 KB Output is correct
29 Correct 4 ms 2680 KB Output is correct
30 Correct 4 ms 2680 KB Output is correct
31 Correct 4 ms 2680 KB Output is correct
32 Correct 4 ms 2680 KB Output is correct
33 Correct 4 ms 2680 KB Output is correct
34 Correct 4 ms 2728 KB Output is correct
35 Correct 4 ms 2680 KB Output is correct
36 Correct 4 ms 2680 KB Output is correct
37 Correct 4 ms 2680 KB Output is correct
38 Correct 4 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 8952 KB Output is correct
2 Correct 68 ms 8952 KB Output is correct
3 Correct 46 ms 6904 KB Output is correct
4 Correct 13 ms 3676 KB Output is correct
5 Correct 12 ms 3320 KB Output is correct
6 Correct 21 ms 4216 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 38 ms 5496 KB Output is correct
9 Correct 45 ms 6136 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 66 ms 7680 KB Output is correct
12 Correct 73 ms 8184 KB Output is correct
13 Correct 4 ms 2808 KB Output is correct
14 Correct 4 ms 2680 KB Output is correct
15 Correct 4 ms 2680 KB Output is correct
16 Correct 4 ms 2680 KB Output is correct
17 Correct 4 ms 2680 KB Output is correct
18 Correct 4 ms 2680 KB Output is correct
19 Correct 4 ms 2680 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 4 ms 2680 KB Output is correct
22 Correct 4 ms 2680 KB Output is correct
23 Correct 4 ms 2680 KB Output is correct
24 Correct 4 ms 2680 KB Output is correct
25 Correct 4 ms 2680 KB Output is correct
26 Correct 4 ms 2680 KB Output is correct
27 Correct 4 ms 2680 KB Output is correct
28 Correct 4 ms 2680 KB Output is correct
29 Correct 4 ms 2680 KB Output is correct
30 Correct 4 ms 2680 KB Output is correct
31 Correct 4 ms 2680 KB Output is correct
32 Correct 4 ms 2680 KB Output is correct
33 Correct 4 ms 2680 KB Output is correct
34 Correct 4 ms 2728 KB Output is correct
35 Correct 4 ms 2680 KB Output is correct
36 Correct 4 ms 2680 KB Output is correct
37 Correct 4 ms 2680 KB Output is correct
38 Correct 4 ms 2680 KB Output is correct
39 Correct 71 ms 8968 KB Output is correct
40 Correct 73 ms 8920 KB Output is correct
41 Correct 46 ms 6904 KB Output is correct
42 Correct 13 ms 3704 KB Output is correct
43 Correct 9 ms 2680 KB Output is correct
44 Correct 4 ms 2680 KB Output is correct
45 Correct 4 ms 2780 KB Output is correct
46 Correct 4 ms 2680 KB Output is correct
47 Correct 4 ms 2680 KB Output is correct
48 Correct 5 ms 2684 KB Output is correct
49 Correct 4 ms 2684 KB Output is correct
50 Correct 4 ms 2680 KB Output is correct
51 Correct 4 ms 2680 KB Output is correct
52 Correct 4 ms 2680 KB Output is correct
53 Correct 4 ms 2680 KB Output is correct
54 Correct 4 ms 2680 KB Output is correct
55 Correct 4 ms 2680 KB Output is correct
56 Correct 4 ms 2680 KB Output is correct
57 Correct 99 ms 10744 KB Output is correct
58 Correct 105 ms 10744 KB Output is correct
59 Correct 97 ms 10664 KB Output is correct
60 Correct 96 ms 10616 KB Output is correct
61 Correct 96 ms 10872 KB Output is correct
62 Correct 101 ms 10872 KB Output is correct
63 Correct 92 ms 10616 KB Output is correct
64 Correct 98 ms 10712 KB Output is correct
65 Correct 95 ms 10872 KB Output is correct
66 Correct 98 ms 10872 KB Output is correct
67 Correct 96 ms 10568 KB Output is correct
68 Correct 101 ms 10616 KB Output is correct
69 Correct 105 ms 11020 KB Output is correct
70 Correct 101 ms 10872 KB Output is correct
71 Correct 4 ms 2680 KB Output is correct
72 Correct 6 ms 2940 KB Output is correct
73 Correct 6 ms 2936 KB Output is correct
74 Correct 6 ms 2936 KB Output is correct
75 Correct 6 ms 2936 KB Output is correct
76 Correct 6 ms 2936 KB Output is correct
77 Correct 6 ms 2936 KB Output is correct
78 Correct 6 ms 2936 KB Output is correct
79 Correct 6 ms 2936 KB Output is correct
80 Correct 99 ms 10744 KB Output is correct
81 Correct 101 ms 10748 KB Output is correct
82 Correct 94 ms 10848 KB Output is correct
83 Correct 98 ms 10872 KB Output is correct
84 Correct 5 ms 2936 KB Output is correct
85 Correct 5 ms 3012 KB Output is correct
86 Correct 6 ms 2908 KB Output is correct
87 Correct 6 ms 2812 KB Output is correct
88 Correct 6 ms 2936 KB Output is correct
89 Correct 6 ms 2936 KB Output is correct
90 Correct 6 ms 2936 KB Output is correct
91 Correct 6 ms 2936 KB Output is correct
92 Correct 6 ms 2936 KB Output is correct
93 Correct 6 ms 2936 KB Output is correct
94 Correct 4 ms 2680 KB Output is correct
95 Correct 4 ms 2680 KB Output is correct
96 Correct 4 ms 2680 KB Output is correct
97 Correct 4 ms 2680 KB Output is correct
98 Correct 4 ms 2680 KB Output is correct
99 Correct 4 ms 2680 KB Output is correct
100 Correct 4 ms 2680 KB Output is correct
101 Correct 4 ms 2680 KB Output is correct
102 Correct 4 ms 2680 KB Output is correct
103 Correct 4 ms 2680 KB Output is correct
104 Correct 12 ms 3448 KB Output is correct
105 Correct 20 ms 4060 KB Output is correct
106 Correct 4 ms 2680 KB Output is correct
107 Correct 36 ms 5368 KB Output is correct
108 Correct 47 ms 6084 KB Output is correct
109 Correct 4 ms 2808 KB Output is correct
110 Correct 64 ms 7672 KB Output is correct
111 Correct 75 ms 8156 KB Output is correct
112 Correct 4 ms 2680 KB Output is correct
113 Correct 100 ms 9824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 31 ms 12644 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 73 ms 8952 KB Output is correct
2 Correct 68 ms 8952 KB Output is correct
3 Correct 46 ms 6904 KB Output is correct
4 Correct 13 ms 3676 KB Output is correct
5 Correct 12 ms 3320 KB Output is correct
6 Correct 21 ms 4216 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 38 ms 5496 KB Output is correct
9 Correct 45 ms 6136 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 66 ms 7680 KB Output is correct
12 Correct 73 ms 8184 KB Output is correct
13 Correct 4 ms 2808 KB Output is correct
14 Runtime error 8 ms 5496 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 73 ms 8952 KB Output is correct
2 Correct 68 ms 8952 KB Output is correct
3 Correct 46 ms 6904 KB Output is correct
4 Correct 13 ms 3676 KB Output is correct
5 Correct 12 ms 3320 KB Output is correct
6 Correct 21 ms 4216 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 38 ms 5496 KB Output is correct
9 Correct 45 ms 6136 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 66 ms 7680 KB Output is correct
12 Correct 73 ms 8184 KB Output is correct
13 Correct 4 ms 2808 KB Output is correct
14 Correct 4 ms 2680 KB Output is correct
15 Correct 4 ms 2680 KB Output is correct
16 Correct 4 ms 2680 KB Output is correct
17 Correct 4 ms 2680 KB Output is correct
18 Correct 4 ms 2680 KB Output is correct
19 Correct 4 ms 2680 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 4 ms 2680 KB Output is correct
22 Correct 4 ms 2680 KB Output is correct
23 Correct 4 ms 2680 KB Output is correct
24 Correct 4 ms 2680 KB Output is correct
25 Correct 4 ms 2680 KB Output is correct
26 Correct 4 ms 2680 KB Output is correct
27 Correct 4 ms 2680 KB Output is correct
28 Correct 4 ms 2680 KB Output is correct
29 Correct 4 ms 2680 KB Output is correct
30 Correct 4 ms 2680 KB Output is correct
31 Correct 4 ms 2680 KB Output is correct
32 Correct 4 ms 2680 KB Output is correct
33 Correct 4 ms 2680 KB Output is correct
34 Correct 4 ms 2728 KB Output is correct
35 Correct 4 ms 2680 KB Output is correct
36 Correct 4 ms 2680 KB Output is correct
37 Correct 4 ms 2680 KB Output is correct
38 Correct 4 ms 2680 KB Output is correct
39 Correct 71 ms 8968 KB Output is correct
40 Correct 73 ms 8920 KB Output is correct
41 Correct 46 ms 6904 KB Output is correct
42 Correct 13 ms 3704 KB Output is correct
43 Correct 9 ms 2680 KB Output is correct
44 Correct 4 ms 2680 KB Output is correct
45 Correct 4 ms 2780 KB Output is correct
46 Correct 4 ms 2680 KB Output is correct
47 Correct 4 ms 2680 KB Output is correct
48 Correct 5 ms 2684 KB Output is correct
49 Correct 4 ms 2684 KB Output is correct
50 Correct 4 ms 2680 KB Output is correct
51 Correct 4 ms 2680 KB Output is correct
52 Correct 4 ms 2680 KB Output is correct
53 Correct 4 ms 2680 KB Output is correct
54 Correct 4 ms 2680 KB Output is correct
55 Correct 4 ms 2680 KB Output is correct
56 Correct 4 ms 2680 KB Output is correct
57 Correct 99 ms 10744 KB Output is correct
58 Correct 105 ms 10744 KB Output is correct
59 Correct 97 ms 10664 KB Output is correct
60 Correct 96 ms 10616 KB Output is correct
61 Correct 96 ms 10872 KB Output is correct
62 Correct 101 ms 10872 KB Output is correct
63 Correct 92 ms 10616 KB Output is correct
64 Correct 98 ms 10712 KB Output is correct
65 Correct 95 ms 10872 KB Output is correct
66 Correct 98 ms 10872 KB Output is correct
67 Correct 96 ms 10568 KB Output is correct
68 Correct 101 ms 10616 KB Output is correct
69 Correct 105 ms 11020 KB Output is correct
70 Correct 101 ms 10872 KB Output is correct
71 Correct 4 ms 2680 KB Output is correct
72 Correct 6 ms 2940 KB Output is correct
73 Correct 6 ms 2936 KB Output is correct
74 Correct 6 ms 2936 KB Output is correct
75 Correct 6 ms 2936 KB Output is correct
76 Correct 6 ms 2936 KB Output is correct
77 Correct 6 ms 2936 KB Output is correct
78 Correct 6 ms 2936 KB Output is correct
79 Correct 6 ms 2936 KB Output is correct
80 Correct 99 ms 10744 KB Output is correct
81 Correct 101 ms 10748 KB Output is correct
82 Correct 94 ms 10848 KB Output is correct
83 Correct 98 ms 10872 KB Output is correct
84 Correct 5 ms 2936 KB Output is correct
85 Correct 5 ms 3012 KB Output is correct
86 Correct 6 ms 2908 KB Output is correct
87 Correct 6 ms 2812 KB Output is correct
88 Correct 6 ms 2936 KB Output is correct
89 Correct 6 ms 2936 KB Output is correct
90 Correct 6 ms 2936 KB Output is correct
91 Correct 6 ms 2936 KB Output is correct
92 Correct 6 ms 2936 KB Output is correct
93 Correct 6 ms 2936 KB Output is correct
94 Correct 4 ms 2680 KB Output is correct
95 Correct 4 ms 2680 KB Output is correct
96 Correct 4 ms 2680 KB Output is correct
97 Correct 4 ms 2680 KB Output is correct
98 Correct 4 ms 2680 KB Output is correct
99 Correct 4 ms 2680 KB Output is correct
100 Correct 4 ms 2680 KB Output is correct
101 Correct 4 ms 2680 KB Output is correct
102 Correct 4 ms 2680 KB Output is correct
103 Correct 4 ms 2680 KB Output is correct
104 Correct 12 ms 3448 KB Output is correct
105 Correct 20 ms 4060 KB Output is correct
106 Correct 4 ms 2680 KB Output is correct
107 Correct 36 ms 5368 KB Output is correct
108 Correct 47 ms 6084 KB Output is correct
109 Correct 4 ms 2808 KB Output is correct
110 Correct 64 ms 7672 KB Output is correct
111 Correct 75 ms 8156 KB Output is correct
112 Correct 4 ms 2680 KB Output is correct
113 Correct 100 ms 9824 KB Output is correct
114 Runtime error 31 ms 12644 KB Execution killed with signal 11 (could be triggered by violating memory limits)
115 Halted 0 ms 0 KB -