#include <bits/stdc++.h>
#include"dreaming.h"
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb push_back
const int nax=1e5+5;
vector<bool> vis(nax);
pair<pair<int,int>,pair<int,int>> dp[nax];
vector<pair<int,int>> adj[nax];
int res=0;
pair<int,int> mx={-1,-1};
void init(int x,int p){
dp[x]={{0,0},{0,0}};
vis[x]=true;
for(auto u:adj[x]){
if(u.fi==p) continue;
init(u.fi,x);
if(u.se+dp[u.fi].fi.fi>dp[x].fi.fi){
dp[x].se=dp[x].fi;
dp[x].fi.fi=dp[u.fi].fi.fi+u.se;
dp[x].fi.se=u.fi;
}else if(u.se+dp[u.fi].fi.fi>dp[x].se.fi){
dp[x].se.fi=dp[u.fi].fi.fi+u.se;
dp[x].se.se=u.fi;
}
}
return;
}
int ans;
void dfs(int x,int p){
res=max(res,dp[x].fi.fi+dp[x].se.fi);
ans=min(ans,dp[x].fi.fi);
for(auto u:adj[x]){
if(u.fi==p) continue;
pair<int,int> cur;
if(u.fi==dp[x].fi.se){
cur=dp[x].se;
cur.fi+=u.se;
cur.se=x;
}else{
cur=dp[x].fi;
cur.fi+=u.se;
cur.se=x;
}
if(cur.fi>dp[u.fi].fi.fi){
dp[u.fi].se=dp[u.fi].fi;
dp[u.fi].fi=cur;
}else if(cur.fi>dp[u.fi].se.fi){
dp[u.fi].se=cur;
}
dfs(u.fi,x);
}
}
int travelTime(int N,int M,int L,int A[],int B[],int T[]){
for (int i = 0; i < M; ++i)
{
adj[A[i]].pb({B[i],T[i]});
adj[B[i]].pb({A[i],T[i]});
}
for (int i = 0; i < N; ++i)
{
if(vis[i]) continue;
init(i,-1);
ans=1e9;
dfs(i,-1);
if(mx.fi<ans){
mx.se=mx.fi;
mx.fi=ans;
}else if(mx.se<ans){
mx.se=ans;
}
}
res=max(res,mx.fi+mx.se+L);
return res;
}/*
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n,m,l;
cin>>n>>m>>l;
int a[m];
int b[m];
int t[m];
for (int i = 0; i < m; ++i)
{
cin>>a[i]>>b[i]>>t[i];
}
cout <<travelTime(n,m,l,a,b,t)<<endl;
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
13296 KB |
Output is correct |
2 |
Correct |
29 ms |
12884 KB |
Output is correct |
3 |
Correct |
23 ms |
11144 KB |
Output is correct |
4 |
Correct |
6 ms |
4188 KB |
Output is correct |
5 |
Correct |
5 ms |
3676 KB |
Output is correct |
6 |
Correct |
10 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
16 ms |
7008 KB |
Output is correct |
9 |
Correct |
21 ms |
9304 KB |
Output is correct |
10 |
Correct |
2 ms |
2816 KB |
Output is correct |
11 |
Correct |
27 ms |
10492 KB |
Output is correct |
12 |
Correct |
39 ms |
11864 KB |
Output is correct |
13 |
Correct |
2 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Correct |
2 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2816 KB |
Output is correct |
4 |
Correct |
2 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
2 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2828 KB |
Output is correct |
13 |
Correct |
1 ms |
2816 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2648 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2648 KB |
Output is correct |
18 |
Correct |
2 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
2 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2648 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
13296 KB |
Output is correct |
2 |
Correct |
29 ms |
12884 KB |
Output is correct |
3 |
Correct |
23 ms |
11144 KB |
Output is correct |
4 |
Correct |
6 ms |
4188 KB |
Output is correct |
5 |
Correct |
5 ms |
3676 KB |
Output is correct |
6 |
Correct |
10 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
16 ms |
7008 KB |
Output is correct |
9 |
Correct |
21 ms |
9304 KB |
Output is correct |
10 |
Correct |
2 ms |
2816 KB |
Output is correct |
11 |
Correct |
27 ms |
10492 KB |
Output is correct |
12 |
Correct |
39 ms |
11864 KB |
Output is correct |
13 |
Correct |
2 ms |
2908 KB |
Output is correct |
14 |
Correct |
2 ms |
2648 KB |
Output is correct |
15 |
Correct |
2 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2816 KB |
Output is correct |
17 |
Correct |
2 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
2 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2828 KB |
Output is correct |
26 |
Correct |
1 ms |
2816 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
1 ms |
2648 KB |
Output is correct |
29 |
Correct |
1 ms |
2648 KB |
Output is correct |
30 |
Correct |
1 ms |
2648 KB |
Output is correct |
31 |
Correct |
2 ms |
2652 KB |
Output is correct |
32 |
Correct |
1 ms |
2652 KB |
Output is correct |
33 |
Correct |
1 ms |
2652 KB |
Output is correct |
34 |
Correct |
1 ms |
2652 KB |
Output is correct |
35 |
Correct |
2 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2652 KB |
Output is correct |
37 |
Correct |
1 ms |
2648 KB |
Output is correct |
38 |
Correct |
1 ms |
2652 KB |
Output is correct |
39 |
Correct |
30 ms |
13144 KB |
Output is correct |
40 |
Correct |
30 ms |
12892 KB |
Output is correct |
41 |
Correct |
24 ms |
11036 KB |
Output is correct |
42 |
Correct |
7 ms |
4188 KB |
Output is correct |
43 |
Correct |
1 ms |
2652 KB |
Output is correct |
44 |
Correct |
1 ms |
2652 KB |
Output is correct |
45 |
Correct |
1 ms |
2648 KB |
Output is correct |
46 |
Correct |
1 ms |
2648 KB |
Output is correct |
47 |
Correct |
1 ms |
2652 KB |
Output is correct |
48 |
Correct |
1 ms |
2816 KB |
Output is correct |
49 |
Correct |
1 ms |
2652 KB |
Output is correct |
50 |
Correct |
1 ms |
2652 KB |
Output is correct |
51 |
Correct |
1 ms |
2652 KB |
Output is correct |
52 |
Correct |
1 ms |
2648 KB |
Output is correct |
53 |
Correct |
1 ms |
2652 KB |
Output is correct |
54 |
Correct |
1 ms |
2816 KB |
Output is correct |
55 |
Correct |
1 ms |
2652 KB |
Output is correct |
56 |
Correct |
1 ms |
2812 KB |
Output is correct |
57 |
Correct |
43 ms |
10888 KB |
Output is correct |
58 |
Correct |
35 ms |
10840 KB |
Output is correct |
59 |
Correct |
42 ms |
10588 KB |
Output is correct |
60 |
Correct |
37 ms |
10580 KB |
Output is correct |
61 |
Correct |
40 ms |
10832 KB |
Output is correct |
62 |
Correct |
40 ms |
10832 KB |
Output is correct |
63 |
Correct |
38 ms |
10320 KB |
Output is correct |
64 |
Correct |
36 ms |
10320 KB |
Output is correct |
65 |
Correct |
40 ms |
10576 KB |
Output is correct |
66 |
Correct |
37 ms |
10844 KB |
Output is correct |
67 |
Correct |
68 ms |
10576 KB |
Output is correct |
68 |
Correct |
41 ms |
10576 KB |
Output is correct |
69 |
Correct |
77 ms |
10940 KB |
Output is correct |
70 |
Correct |
48 ms |
10836 KB |
Output is correct |
71 |
Correct |
1 ms |
2648 KB |
Output is correct |
72 |
Correct |
2 ms |
2904 KB |
Output is correct |
73 |
Correct |
2 ms |
2908 KB |
Output is correct |
74 |
Correct |
2 ms |
2876 KB |
Output is correct |
75 |
Correct |
3 ms |
2904 KB |
Output is correct |
76 |
Correct |
3 ms |
3168 KB |
Output is correct |
77 |
Correct |
4 ms |
2904 KB |
Output is correct |
78 |
Correct |
2 ms |
2908 KB |
Output is correct |
79 |
Correct |
3 ms |
2876 KB |
Output is correct |
80 |
Correct |
37 ms |
10564 KB |
Output is correct |
81 |
Correct |
41 ms |
10584 KB |
Output is correct |
82 |
Correct |
59 ms |
10836 KB |
Output is correct |
83 |
Correct |
36 ms |
10836 KB |
Output is correct |
84 |
Correct |
2 ms |
2860 KB |
Output is correct |
85 |
Correct |
2 ms |
2828 KB |
Output is correct |
86 |
Correct |
3 ms |
2908 KB |
Output is correct |
87 |
Correct |
2 ms |
3160 KB |
Output is correct |
88 |
Correct |
2 ms |
2908 KB |
Output is correct |
89 |
Correct |
2 ms |
2908 KB |
Output is correct |
90 |
Correct |
2 ms |
2908 KB |
Output is correct |
91 |
Correct |
2 ms |
2908 KB |
Output is correct |
92 |
Correct |
3 ms |
2904 KB |
Output is correct |
93 |
Correct |
2 ms |
2904 KB |
Output is correct |
94 |
Correct |
1 ms |
2652 KB |
Output is correct |
95 |
Correct |
2 ms |
2652 KB |
Output is correct |
96 |
Correct |
1 ms |
2652 KB |
Output is correct |
97 |
Correct |
1 ms |
2816 KB |
Output is correct |
98 |
Correct |
2 ms |
2820 KB |
Output is correct |
99 |
Correct |
2 ms |
2652 KB |
Output is correct |
100 |
Correct |
1 ms |
2776 KB |
Output is correct |
101 |
Correct |
2 ms |
2904 KB |
Output is correct |
102 |
Correct |
2 ms |
2652 KB |
Output is correct |
103 |
Correct |
1 ms |
2652 KB |
Output is correct |
104 |
Correct |
5 ms |
3676 KB |
Output is correct |
105 |
Correct |
10 ms |
5024 KB |
Output is correct |
106 |
Correct |
1 ms |
2652 KB |
Output is correct |
107 |
Correct |
17 ms |
7004 KB |
Output is correct |
108 |
Correct |
21 ms |
9472 KB |
Output is correct |
109 |
Correct |
1 ms |
2908 KB |
Output is correct |
110 |
Correct |
33 ms |
10588 KB |
Output is correct |
111 |
Correct |
40 ms |
11864 KB |
Output is correct |
112 |
Correct |
2 ms |
2908 KB |
Output is correct |
113 |
Correct |
42 ms |
17912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
7000 KB |
Output is correct |
2 |
Incorrect |
12 ms |
7004 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Correct |
2 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2816 KB |
Output is correct |
4 |
Correct |
2 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
2 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2828 KB |
Output is correct |
13 |
Correct |
1 ms |
2816 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2648 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2648 KB |
Output is correct |
18 |
Correct |
2 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
2 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2648 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
2 ms |
2908 KB |
Output is correct |
28 |
Correct |
2 ms |
2908 KB |
Output is correct |
29 |
Correct |
2 ms |
2652 KB |
Output is correct |
30 |
Correct |
2 ms |
2908 KB |
Output is correct |
31 |
Correct |
2 ms |
2908 KB |
Output is correct |
32 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
13296 KB |
Output is correct |
2 |
Correct |
29 ms |
12884 KB |
Output is correct |
3 |
Correct |
23 ms |
11144 KB |
Output is correct |
4 |
Correct |
6 ms |
4188 KB |
Output is correct |
5 |
Correct |
5 ms |
3676 KB |
Output is correct |
6 |
Correct |
10 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
16 ms |
7008 KB |
Output is correct |
9 |
Correct |
21 ms |
9304 KB |
Output is correct |
10 |
Correct |
2 ms |
2816 KB |
Output is correct |
11 |
Correct |
27 ms |
10492 KB |
Output is correct |
12 |
Correct |
39 ms |
11864 KB |
Output is correct |
13 |
Correct |
2 ms |
2908 KB |
Output is correct |
14 |
Correct |
2 ms |
2648 KB |
Output is correct |
15 |
Correct |
2 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2816 KB |
Output is correct |
17 |
Correct |
2 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
2 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2828 KB |
Output is correct |
26 |
Correct |
1 ms |
2816 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
1 ms |
2648 KB |
Output is correct |
29 |
Correct |
1 ms |
2648 KB |
Output is correct |
30 |
Correct |
1 ms |
2648 KB |
Output is correct |
31 |
Correct |
2 ms |
2652 KB |
Output is correct |
32 |
Correct |
1 ms |
2652 KB |
Output is correct |
33 |
Correct |
1 ms |
2652 KB |
Output is correct |
34 |
Correct |
1 ms |
2652 KB |
Output is correct |
35 |
Correct |
2 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2652 KB |
Output is correct |
37 |
Correct |
1 ms |
2648 KB |
Output is correct |
38 |
Correct |
1 ms |
2652 KB |
Output is correct |
39 |
Correct |
30 ms |
13144 KB |
Output is correct |
40 |
Correct |
30 ms |
12892 KB |
Output is correct |
41 |
Correct |
24 ms |
11036 KB |
Output is correct |
42 |
Correct |
7 ms |
4188 KB |
Output is correct |
43 |
Correct |
1 ms |
2652 KB |
Output is correct |
44 |
Correct |
1 ms |
2652 KB |
Output is correct |
45 |
Correct |
1 ms |
2648 KB |
Output is correct |
46 |
Correct |
1 ms |
2648 KB |
Output is correct |
47 |
Correct |
1 ms |
2652 KB |
Output is correct |
48 |
Correct |
1 ms |
2816 KB |
Output is correct |
49 |
Correct |
1 ms |
2652 KB |
Output is correct |
50 |
Correct |
1 ms |
2652 KB |
Output is correct |
51 |
Correct |
1 ms |
2652 KB |
Output is correct |
52 |
Correct |
1 ms |
2648 KB |
Output is correct |
53 |
Correct |
1 ms |
2652 KB |
Output is correct |
54 |
Correct |
1 ms |
2816 KB |
Output is correct |
55 |
Correct |
1 ms |
2652 KB |
Output is correct |
56 |
Correct |
1 ms |
2812 KB |
Output is correct |
57 |
Correct |
43 ms |
10888 KB |
Output is correct |
58 |
Correct |
35 ms |
10840 KB |
Output is correct |
59 |
Correct |
42 ms |
10588 KB |
Output is correct |
60 |
Correct |
37 ms |
10580 KB |
Output is correct |
61 |
Correct |
40 ms |
10832 KB |
Output is correct |
62 |
Correct |
40 ms |
10832 KB |
Output is correct |
63 |
Correct |
38 ms |
10320 KB |
Output is correct |
64 |
Correct |
36 ms |
10320 KB |
Output is correct |
65 |
Correct |
40 ms |
10576 KB |
Output is correct |
66 |
Correct |
37 ms |
10844 KB |
Output is correct |
67 |
Correct |
68 ms |
10576 KB |
Output is correct |
68 |
Correct |
41 ms |
10576 KB |
Output is correct |
69 |
Correct |
77 ms |
10940 KB |
Output is correct |
70 |
Correct |
48 ms |
10836 KB |
Output is correct |
71 |
Correct |
1 ms |
2648 KB |
Output is correct |
72 |
Correct |
2 ms |
2904 KB |
Output is correct |
73 |
Correct |
2 ms |
2908 KB |
Output is correct |
74 |
Correct |
2 ms |
2876 KB |
Output is correct |
75 |
Correct |
3 ms |
2904 KB |
Output is correct |
76 |
Correct |
3 ms |
3168 KB |
Output is correct |
77 |
Correct |
4 ms |
2904 KB |
Output is correct |
78 |
Correct |
2 ms |
2908 KB |
Output is correct |
79 |
Correct |
3 ms |
2876 KB |
Output is correct |
80 |
Correct |
37 ms |
10564 KB |
Output is correct |
81 |
Correct |
41 ms |
10584 KB |
Output is correct |
82 |
Correct |
59 ms |
10836 KB |
Output is correct |
83 |
Correct |
36 ms |
10836 KB |
Output is correct |
84 |
Correct |
2 ms |
2860 KB |
Output is correct |
85 |
Correct |
2 ms |
2828 KB |
Output is correct |
86 |
Correct |
3 ms |
2908 KB |
Output is correct |
87 |
Correct |
2 ms |
3160 KB |
Output is correct |
88 |
Correct |
2 ms |
2908 KB |
Output is correct |
89 |
Correct |
2 ms |
2908 KB |
Output is correct |
90 |
Correct |
2 ms |
2908 KB |
Output is correct |
91 |
Correct |
2 ms |
2908 KB |
Output is correct |
92 |
Correct |
3 ms |
2904 KB |
Output is correct |
93 |
Correct |
2 ms |
2904 KB |
Output is correct |
94 |
Correct |
1 ms |
2652 KB |
Output is correct |
95 |
Correct |
2 ms |
2652 KB |
Output is correct |
96 |
Correct |
1 ms |
2652 KB |
Output is correct |
97 |
Correct |
1 ms |
2816 KB |
Output is correct |
98 |
Correct |
2 ms |
2820 KB |
Output is correct |
99 |
Correct |
2 ms |
2652 KB |
Output is correct |
100 |
Correct |
1 ms |
2776 KB |
Output is correct |
101 |
Correct |
2 ms |
2904 KB |
Output is correct |
102 |
Correct |
2 ms |
2652 KB |
Output is correct |
103 |
Correct |
1 ms |
2652 KB |
Output is correct |
104 |
Correct |
5 ms |
3676 KB |
Output is correct |
105 |
Correct |
10 ms |
5024 KB |
Output is correct |
106 |
Correct |
1 ms |
2652 KB |
Output is correct |
107 |
Correct |
17 ms |
7004 KB |
Output is correct |
108 |
Correct |
21 ms |
9472 KB |
Output is correct |
109 |
Correct |
1 ms |
2908 KB |
Output is correct |
110 |
Correct |
33 ms |
10588 KB |
Output is correct |
111 |
Correct |
40 ms |
11864 KB |
Output is correct |
112 |
Correct |
2 ms |
2908 KB |
Output is correct |
113 |
Correct |
42 ms |
17912 KB |
Output is correct |
114 |
Correct |
16 ms |
7000 KB |
Output is correct |
115 |
Incorrect |
12 ms |
7004 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |