답안 #508767

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
508767 2022-01-13T17:30:44 Z Gurban 꿈 (IOI13_dreaming) C++17
47 / 100
64 ms 18664 KB
#include "bits/stdc++.h"
#include "dreaming.h"
using namespace std;

const int maxn=1e5+5;
int idx,jog,ans;
int dp[maxn][2];
bool vis[maxn];
vector<pair<int,int>>E[maxn];

void calc(int nd,int pr){
    vis[nd] = 1;
    int a = 0,b = 0;
    for(auto i : E[nd]){
        if(i.first == pr) continue;
        calc(i.first,nd);
        if(dp[i.first][0] + i.second > a) b=a,a = dp[i.first][0] + i.second;
        else if(dp[i.first][0] + i.second > b) b=dp[i.first][0] + i.second;
    }
    dp[nd][0] = a;
    dp[nd][1] = b;
    ans = max(ans,a + b);
}

void dfs(int nd,int pr,int yok){
    vis[nd] = 1;
    if(max(yok,dp[nd][0]) < jog){
        idx = nd;
        jog = max(yok,dp[nd][0]);
    }
    for(auto i : E[nd]){
        if(i.first == pr) continue;
        if(dp[i.first][0] + i.second == dp[nd][0]) dfs(i.first,nd,max(yok,dp[nd][1])+i.second);
        else dfs(i.first,nd,max(yok,dp[nd][0])+i.second);
    }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for(int i = 0;i < M;i++){
        E[A[i]].push_back({B[i],T[i]});
        E[B[i]].push_back({A[i],T[i]});
    }
    for(int i = 0;i < N;i++) if(!vis[i]) calc(i,0);
    memset(vis,0,sizeof(vis));
    vector<pair<int,int>>v;
    for(int i = 0;i < N;i++){
        if(vis[i]) continue;
        idx = -1;
        jog = 1e9;
        dfs(i,-1,0);
        v.push_back({jog,idx});
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    if(M != N-1) ans = max(ans,v[0].first + v[1].first + L);
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 12080 KB Output is correct
2 Correct 42 ms 12996 KB Output is correct
3 Correct 28 ms 11488 KB Output is correct
4 Correct 7 ms 4216 KB Output is correct
5 Correct 5 ms 3660 KB Output is correct
6 Correct 12 ms 5044 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 20 ms 7116 KB Output is correct
9 Correct 27 ms 9620 KB Output is correct
10 Correct 2 ms 2788 KB Output is correct
11 Correct 38 ms 10504 KB Output is correct
12 Correct 45 ms 11724 KB Output is correct
13 Correct 2 ms 2764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2764 KB Output is correct
2 Correct 2 ms 2648 KB Output is correct
3 Correct 2 ms 2656 KB Output is correct
4 Correct 2 ms 2764 KB Output is correct
5 Correct 2 ms 2880 KB Output is correct
6 Correct 2 ms 2656 KB Output is correct
7 Correct 2 ms 2764 KB Output is correct
8 Correct 2 ms 2764 KB Output is correct
9 Correct 2 ms 2652 KB Output is correct
10 Correct 2 ms 2764 KB Output is correct
11 Correct 2 ms 2764 KB Output is correct
12 Correct 1 ms 2660 KB Output is correct
13 Correct 2 ms 2656 KB Output is correct
14 Correct 2 ms 2656 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 1 ms 2764 KB Output is correct
17 Correct 2 ms 2764 KB Output is correct
18 Correct 2 ms 2764 KB Output is correct
19 Correct 2 ms 2656 KB Output is correct
20 Correct 2 ms 2764 KB Output is correct
21 Correct 2 ms 2764 KB Output is correct
22 Correct 2 ms 2764 KB Output is correct
23 Correct 1 ms 2764 KB Output is correct
24 Correct 2 ms 2764 KB Output is correct
25 Correct 2 ms 2764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 12080 KB Output is correct
2 Correct 42 ms 12996 KB Output is correct
3 Correct 28 ms 11488 KB Output is correct
4 Correct 7 ms 4216 KB Output is correct
5 Correct 5 ms 3660 KB Output is correct
6 Correct 12 ms 5044 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 20 ms 7116 KB Output is correct
9 Correct 27 ms 9620 KB Output is correct
10 Correct 2 ms 2788 KB Output is correct
11 Correct 38 ms 10504 KB Output is correct
12 Correct 45 ms 11724 KB Output is correct
13 Correct 2 ms 2764 KB Output is correct
14 Correct 1 ms 2764 KB Output is correct
15 Correct 2 ms 2648 KB Output is correct
16 Correct 2 ms 2656 KB Output is correct
17 Correct 2 ms 2764 KB Output is correct
18 Correct 2 ms 2880 KB Output is correct
19 Correct 2 ms 2656 KB Output is correct
20 Correct 2 ms 2764 KB Output is correct
21 Correct 2 ms 2764 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 2 ms 2764 KB Output is correct
24 Correct 2 ms 2764 KB Output is correct
25 Correct 1 ms 2660 KB Output is correct
26 Correct 2 ms 2656 KB Output is correct
27 Correct 2 ms 2656 KB Output is correct
28 Correct 2 ms 2636 KB Output is correct
29 Correct 1 ms 2764 KB Output is correct
30 Correct 2 ms 2764 KB Output is correct
31 Correct 2 ms 2764 KB Output is correct
32 Correct 2 ms 2656 KB Output is correct
33 Correct 2 ms 2764 KB Output is correct
34 Correct 2 ms 2764 KB Output is correct
35 Correct 2 ms 2764 KB Output is correct
36 Correct 1 ms 2764 KB Output is correct
37 Correct 2 ms 2764 KB Output is correct
38 Correct 2 ms 2764 KB Output is correct
39 Correct 46 ms 13268 KB Output is correct
40 Correct 44 ms 12940 KB Output is correct
41 Correct 28 ms 11460 KB Output is correct
42 Correct 7 ms 4300 KB Output is correct
43 Correct 1 ms 2636 KB Output is correct
44 Correct 2 ms 2648 KB Output is correct
45 Correct 1 ms 2764 KB Output is correct
46 Correct 2 ms 2764 KB Output is correct
47 Correct 2 ms 2652 KB Output is correct
48 Correct 1 ms 2660 KB Output is correct
49 Correct 2 ms 2764 KB Output is correct
50 Correct 2 ms 2764 KB Output is correct
51 Correct 2 ms 2764 KB Output is correct
52 Correct 1 ms 2764 KB Output is correct
53 Correct 1 ms 2764 KB Output is correct
54 Correct 2 ms 2764 KB Output is correct
55 Correct 2 ms 2656 KB Output is correct
56 Correct 1 ms 2656 KB Output is correct
57 Correct 54 ms 10076 KB Output is correct
58 Correct 60 ms 9976 KB Output is correct
59 Correct 54 ms 9924 KB Output is correct
60 Correct 54 ms 9964 KB Output is correct
61 Correct 54 ms 10012 KB Output is correct
62 Correct 51 ms 10052 KB Output is correct
63 Correct 54 ms 9684 KB Output is correct
64 Correct 50 ms 9652 KB Output is correct
65 Correct 51 ms 9956 KB Output is correct
66 Correct 52 ms 9940 KB Output is correct
67 Correct 54 ms 9908 KB Output is correct
68 Correct 56 ms 9928 KB Output is correct
69 Correct 54 ms 10216 KB Output is correct
70 Correct 60 ms 10188 KB Output is correct
71 Correct 1 ms 2636 KB Output is correct
72 Correct 3 ms 2924 KB Output is correct
73 Correct 3 ms 2892 KB Output is correct
74 Correct 3 ms 2892 KB Output is correct
75 Correct 3 ms 2892 KB Output is correct
76 Correct 3 ms 2924 KB Output is correct
77 Correct 3 ms 3012 KB Output is correct
78 Correct 3 ms 2892 KB Output is correct
79 Correct 3 ms 2892 KB Output is correct
80 Correct 54 ms 9924 KB Output is correct
81 Correct 60 ms 9956 KB Output is correct
82 Correct 53 ms 9924 KB Output is correct
83 Correct 52 ms 9956 KB Output is correct
84 Correct 2 ms 2892 KB Output is correct
85 Correct 3 ms 2800 KB Output is correct
86 Correct 3 ms 2892 KB Output is correct
87 Correct 2 ms 2892 KB Output is correct
88 Correct 3 ms 2924 KB Output is correct
89 Correct 3 ms 2892 KB Output is correct
90 Correct 2 ms 2892 KB Output is correct
91 Correct 3 ms 2920 KB Output is correct
92 Correct 3 ms 2892 KB Output is correct
93 Correct 3 ms 2892 KB Output is correct
94 Correct 1 ms 2764 KB Output is correct
95 Correct 1 ms 2652 KB Output is correct
96 Correct 2 ms 2764 KB Output is correct
97 Correct 2 ms 2764 KB Output is correct
98 Correct 1 ms 2764 KB Output is correct
99 Correct 2 ms 2764 KB Output is correct
100 Correct 2 ms 2764 KB Output is correct
101 Correct 1 ms 2764 KB Output is correct
102 Correct 2 ms 2656 KB Output is correct
103 Correct 2 ms 2664 KB Output is correct
104 Correct 5 ms 3660 KB Output is correct
105 Correct 11 ms 5088 KB Output is correct
106 Correct 2 ms 2764 KB Output is correct
107 Correct 22 ms 7012 KB Output is correct
108 Correct 27 ms 9524 KB Output is correct
109 Correct 2 ms 2764 KB Output is correct
110 Correct 39 ms 10464 KB Output is correct
111 Correct 50 ms 11760 KB Output is correct
112 Correct 2 ms 2764 KB Output is correct
113 Correct 64 ms 18664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 6368 KB Output is correct
2 Incorrect 23 ms 6368 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2764 KB Output is correct
2 Correct 2 ms 2648 KB Output is correct
3 Correct 2 ms 2656 KB Output is correct
4 Correct 2 ms 2764 KB Output is correct
5 Correct 2 ms 2880 KB Output is correct
6 Correct 2 ms 2656 KB Output is correct
7 Correct 2 ms 2764 KB Output is correct
8 Correct 2 ms 2764 KB Output is correct
9 Correct 2 ms 2652 KB Output is correct
10 Correct 2 ms 2764 KB Output is correct
11 Correct 2 ms 2764 KB Output is correct
12 Correct 1 ms 2660 KB Output is correct
13 Correct 2 ms 2656 KB Output is correct
14 Correct 2 ms 2656 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 1 ms 2764 KB Output is correct
17 Correct 2 ms 2764 KB Output is correct
18 Correct 2 ms 2764 KB Output is correct
19 Correct 2 ms 2656 KB Output is correct
20 Correct 2 ms 2764 KB Output is correct
21 Correct 2 ms 2764 KB Output is correct
22 Correct 2 ms 2764 KB Output is correct
23 Correct 1 ms 2764 KB Output is correct
24 Correct 2 ms 2764 KB Output is correct
25 Correct 2 ms 2764 KB Output is correct
26 Correct 3 ms 2764 KB Output is correct
27 Correct 2 ms 2764 KB Output is correct
28 Correct 3 ms 2828 KB Output is correct
29 Correct 3 ms 2764 KB Output is correct
30 Correct 2 ms 2892 KB Output is correct
31 Correct 3 ms 2912 KB Output is correct
32 Incorrect 2 ms 2788 KB Output isn't correct
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 12080 KB Output is correct
2 Correct 42 ms 12996 KB Output is correct
3 Correct 28 ms 11488 KB Output is correct
4 Correct 7 ms 4216 KB Output is correct
5 Correct 5 ms 3660 KB Output is correct
6 Correct 12 ms 5044 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 20 ms 7116 KB Output is correct
9 Correct 27 ms 9620 KB Output is correct
10 Correct 2 ms 2788 KB Output is correct
11 Correct 38 ms 10504 KB Output is correct
12 Correct 45 ms 11724 KB Output is correct
13 Correct 2 ms 2764 KB Output is correct
14 Correct 1 ms 2764 KB Output is correct
15 Correct 2 ms 2648 KB Output is correct
16 Correct 2 ms 2656 KB Output is correct
17 Correct 2 ms 2764 KB Output is correct
18 Correct 2 ms 2880 KB Output is correct
19 Correct 2 ms 2656 KB Output is correct
20 Correct 2 ms 2764 KB Output is correct
21 Correct 2 ms 2764 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 2 ms 2764 KB Output is correct
24 Correct 2 ms 2764 KB Output is correct
25 Correct 1 ms 2660 KB Output is correct
26 Correct 2 ms 2656 KB Output is correct
27 Correct 2 ms 2656 KB Output is correct
28 Correct 2 ms 2636 KB Output is correct
29 Correct 1 ms 2764 KB Output is correct
30 Correct 2 ms 2764 KB Output is correct
31 Correct 2 ms 2764 KB Output is correct
32 Correct 2 ms 2656 KB Output is correct
33 Correct 2 ms 2764 KB Output is correct
34 Correct 2 ms 2764 KB Output is correct
35 Correct 2 ms 2764 KB Output is correct
36 Correct 1 ms 2764 KB Output is correct
37 Correct 2 ms 2764 KB Output is correct
38 Correct 2 ms 2764 KB Output is correct
39 Correct 46 ms 13268 KB Output is correct
40 Correct 44 ms 12940 KB Output is correct
41 Correct 28 ms 11460 KB Output is correct
42 Correct 7 ms 4300 KB Output is correct
43 Correct 1 ms 2636 KB Output is correct
44 Correct 2 ms 2648 KB Output is correct
45 Correct 1 ms 2764 KB Output is correct
46 Correct 2 ms 2764 KB Output is correct
47 Correct 2 ms 2652 KB Output is correct
48 Correct 1 ms 2660 KB Output is correct
49 Correct 2 ms 2764 KB Output is correct
50 Correct 2 ms 2764 KB Output is correct
51 Correct 2 ms 2764 KB Output is correct
52 Correct 1 ms 2764 KB Output is correct
53 Correct 1 ms 2764 KB Output is correct
54 Correct 2 ms 2764 KB Output is correct
55 Correct 2 ms 2656 KB Output is correct
56 Correct 1 ms 2656 KB Output is correct
57 Correct 54 ms 10076 KB Output is correct
58 Correct 60 ms 9976 KB Output is correct
59 Correct 54 ms 9924 KB Output is correct
60 Correct 54 ms 9964 KB Output is correct
61 Correct 54 ms 10012 KB Output is correct
62 Correct 51 ms 10052 KB Output is correct
63 Correct 54 ms 9684 KB Output is correct
64 Correct 50 ms 9652 KB Output is correct
65 Correct 51 ms 9956 KB Output is correct
66 Correct 52 ms 9940 KB Output is correct
67 Correct 54 ms 9908 KB Output is correct
68 Correct 56 ms 9928 KB Output is correct
69 Correct 54 ms 10216 KB Output is correct
70 Correct 60 ms 10188 KB Output is correct
71 Correct 1 ms 2636 KB Output is correct
72 Correct 3 ms 2924 KB Output is correct
73 Correct 3 ms 2892 KB Output is correct
74 Correct 3 ms 2892 KB Output is correct
75 Correct 3 ms 2892 KB Output is correct
76 Correct 3 ms 2924 KB Output is correct
77 Correct 3 ms 3012 KB Output is correct
78 Correct 3 ms 2892 KB Output is correct
79 Correct 3 ms 2892 KB Output is correct
80 Correct 54 ms 9924 KB Output is correct
81 Correct 60 ms 9956 KB Output is correct
82 Correct 53 ms 9924 KB Output is correct
83 Correct 52 ms 9956 KB Output is correct
84 Correct 2 ms 2892 KB Output is correct
85 Correct 3 ms 2800 KB Output is correct
86 Correct 3 ms 2892 KB Output is correct
87 Correct 2 ms 2892 KB Output is correct
88 Correct 3 ms 2924 KB Output is correct
89 Correct 3 ms 2892 KB Output is correct
90 Correct 2 ms 2892 KB Output is correct
91 Correct 3 ms 2920 KB Output is correct
92 Correct 3 ms 2892 KB Output is correct
93 Correct 3 ms 2892 KB Output is correct
94 Correct 1 ms 2764 KB Output is correct
95 Correct 1 ms 2652 KB Output is correct
96 Correct 2 ms 2764 KB Output is correct
97 Correct 2 ms 2764 KB Output is correct
98 Correct 1 ms 2764 KB Output is correct
99 Correct 2 ms 2764 KB Output is correct
100 Correct 2 ms 2764 KB Output is correct
101 Correct 1 ms 2764 KB Output is correct
102 Correct 2 ms 2656 KB Output is correct
103 Correct 2 ms 2664 KB Output is correct
104 Correct 5 ms 3660 KB Output is correct
105 Correct 11 ms 5088 KB Output is correct
106 Correct 2 ms 2764 KB Output is correct
107 Correct 22 ms 7012 KB Output is correct
108 Correct 27 ms 9524 KB Output is correct
109 Correct 2 ms 2764 KB Output is correct
110 Correct 39 ms 10464 KB Output is correct
111 Correct 50 ms 11760 KB Output is correct
112 Correct 2 ms 2764 KB Output is correct
113 Correct 64 ms 18664 KB Output is correct
114 Correct 24 ms 6368 KB Output is correct
115 Incorrect 23 ms 6368 KB Output isn't correct
116 Halted 0 ms 0 KB -