# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
154052 |
2019-09-18T02:15:27 Z |
gratus907 |
None (KOI18_robot) |
C++17 |
|
1000 ms |
9120 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define ll long long
#define eps 1e-7
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
typedef pair <int, int> pii;
int n, a, b;
vector <pii> graph[101010];
vector <int> stk;
bool visit[101010];
int dist[101010];
int main()
{
usecppio
cin >> n;
cin >> a >> b;
for (int i = 1; i<n; i++)
{
int u, v, w;
cin >> u >> v >> w;
graph[u].push_back({v,w});
graph[v].push_back({u,w});
}
stk.push_back(a);
visit[a] = 1;
dist[a] = 0;
while(!stk.empty())
{
int x = stk.back();
if (x==b)
break;
bool flag = false;
for (auto it:graph[x])
{
if (!visit[it.first])
{
flag = true;
visit[it.first] = 1;
dist[it.first] = (dist[x] + it.second);
stk.push_back(it.first);
break;
}
}
if (!flag)
stk.pop_back();
}
int mm = 0;
int s = stk.size();
for (int i = 1; i<s; i++)
mm = max(mm, dist[stk[i]]-dist[stk[i-1]]);
cout << dist[stk.back()]-mm;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
8432 KB |
Output is correct |
2 |
Correct |
48 ms |
7416 KB |
Output is correct |
3 |
Correct |
45 ms |
7416 KB |
Output is correct |
4 |
Correct |
4 ms |
2808 KB |
Output is correct |
5 |
Correct |
10 ms |
3448 KB |
Output is correct |
6 |
Correct |
11 ms |
3576 KB |
Output is correct |
7 |
Correct |
5 ms |
2680 KB |
Output is correct |
8 |
Correct |
13 ms |
3704 KB |
Output is correct |
9 |
Correct |
5 ms |
2808 KB |
Output is correct |
10 |
Correct |
15 ms |
3960 KB |
Output is correct |
11 |
Correct |
5 ms |
2680 KB |
Output is correct |
12 |
Correct |
4 ms |
2680 KB |
Output is correct |
13 |
Correct |
17 ms |
4348 KB |
Output is correct |
14 |
Correct |
20 ms |
4728 KB |
Output is correct |
15 |
Correct |
7 ms |
2936 KB |
Output is correct |
16 |
Correct |
26 ms |
4984 KB |
Output is correct |
17 |
Correct |
25 ms |
5496 KB |
Output is correct |
18 |
Correct |
29 ms |
5876 KB |
Output is correct |
19 |
Correct |
7 ms |
2936 KB |
Output is correct |
20 |
Correct |
31 ms |
6136 KB |
Output is correct |
21 |
Correct |
36 ms |
6688 KB |
Output is correct |
22 |
Correct |
38 ms |
6756 KB |
Output is correct |
23 |
Correct |
8 ms |
3192 KB |
Output is correct |
24 |
Correct |
44 ms |
7032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
8824 KB |
Output is correct |
2 |
Correct |
44 ms |
7416 KB |
Output is correct |
3 |
Correct |
5 ms |
2808 KB |
Output is correct |
4 |
Correct |
5 ms |
2808 KB |
Output is correct |
5 |
Correct |
12 ms |
3704 KB |
Output is correct |
6 |
Correct |
11 ms |
3576 KB |
Output is correct |
7 |
Correct |
4 ms |
2808 KB |
Output is correct |
8 |
Correct |
14 ms |
3960 KB |
Output is correct |
9 |
Correct |
95 ms |
4212 KB |
Output is correct |
10 |
Correct |
5 ms |
2680 KB |
Output is correct |
11 |
Correct |
21 ms |
4728 KB |
Output is correct |
12 |
Correct |
28 ms |
4728 KB |
Output is correct |
13 |
Correct |
7 ms |
2936 KB |
Output is correct |
14 |
Correct |
8 ms |
2936 KB |
Output is correct |
15 |
Correct |
31 ms |
5652 KB |
Output is correct |
16 |
Correct |
26 ms |
5496 KB |
Output is correct |
17 |
Correct |
35 ms |
6140 KB |
Output is correct |
18 |
Correct |
521 ms |
6384 KB |
Output is correct |
19 |
Correct |
37 ms |
6776 KB |
Output is correct |
20 |
Correct |
52 ms |
7288 KB |
Output is correct |
21 |
Correct |
8 ms |
3192 KB |
Output is correct |
22 |
Correct |
8 ms |
3192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2808 KB |
Output is correct |
2 |
Correct |
5 ms |
2808 KB |
Output is correct |
3 |
Correct |
5 ms |
2808 KB |
Output is correct |
4 |
Correct |
4 ms |
2680 KB |
Output is correct |
5 |
Correct |
5 ms |
2808 KB |
Output is correct |
6 |
Correct |
5 ms |
2808 KB |
Output is correct |
7 |
Correct |
7 ms |
2808 KB |
Output is correct |
8 |
Correct |
4 ms |
2808 KB |
Output is correct |
9 |
Correct |
4 ms |
2808 KB |
Output is correct |
10 |
Correct |
6 ms |
2900 KB |
Output is correct |
11 |
Correct |
6 ms |
2936 KB |
Output is correct |
12 |
Correct |
6 ms |
2936 KB |
Output is correct |
13 |
Correct |
9 ms |
2936 KB |
Output is correct |
14 |
Correct |
6 ms |
2936 KB |
Output is correct |
15 |
Correct |
7 ms |
3064 KB |
Output is correct |
16 |
Correct |
4 ms |
2680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
9120 KB |
Output is correct |
2 |
Correct |
59 ms |
8824 KB |
Output is correct |
3 |
Correct |
49 ms |
8448 KB |
Output is correct |
4 |
Correct |
45 ms |
7416 KB |
Output is correct |
5 |
Correct |
44 ms |
7416 KB |
Output is correct |
6 |
Correct |
87 ms |
8476 KB |
Output is correct |
7 |
Correct |
5 ms |
2808 KB |
Output is correct |
8 |
Correct |
5 ms |
2808 KB |
Output is correct |
9 |
Correct |
5 ms |
2808 KB |
Output is correct |
10 |
Correct |
10 ms |
3448 KB |
Output is correct |
11 |
Correct |
5 ms |
2808 KB |
Output is correct |
12 |
Correct |
13 ms |
3704 KB |
Output is correct |
13 |
Correct |
13 ms |
3672 KB |
Output is correct |
14 |
Correct |
11 ms |
3576 KB |
Output is correct |
15 |
Correct |
4 ms |
2680 KB |
Output is correct |
16 |
Correct |
6 ms |
2808 KB |
Output is correct |
17 |
Correct |
13 ms |
3704 KB |
Output is correct |
18 |
Correct |
5 ms |
2808 KB |
Output is correct |
19 |
Correct |
16 ms |
4088 KB |
Output is correct |
20 |
Correct |
65 ms |
4132 KB |
Output is correct |
21 |
Correct |
98 ms |
4084 KB |
Output is correct |
22 |
Correct |
8 ms |
2808 KB |
Output is correct |
23 |
Correct |
5 ms |
2760 KB |
Output is correct |
24 |
Correct |
4 ms |
2680 KB |
Output is correct |
25 |
Correct |
7 ms |
3064 KB |
Output is correct |
26 |
Correct |
17 ms |
4216 KB |
Output is correct |
27 |
Correct |
6 ms |
2936 KB |
Output is correct |
28 |
Correct |
21 ms |
4728 KB |
Output is correct |
29 |
Correct |
30 ms |
4728 KB |
Output is correct |
30 |
Correct |
37 ms |
4720 KB |
Output is correct |
31 |
Correct |
6 ms |
2936 KB |
Output is correct |
32 |
Correct |
10 ms |
2936 KB |
Output is correct |
33 |
Correct |
8 ms |
2936 KB |
Output is correct |
34 |
Correct |
22 ms |
4984 KB |
Output is correct |
35 |
Correct |
7 ms |
2936 KB |
Output is correct |
36 |
Correct |
33 ms |
5724 KB |
Output is correct |
37 |
Correct |
31 ms |
5752 KB |
Output is correct |
38 |
Correct |
25 ms |
5496 KB |
Output is correct |
39 |
Correct |
7 ms |
3064 KB |
Output is correct |
40 |
Correct |
5 ms |
2808 KB |
Output is correct |
41 |
Correct |
29 ms |
5748 KB |
Output is correct |
42 |
Correct |
8 ms |
3068 KB |
Output is correct |
43 |
Correct |
31 ms |
6136 KB |
Output is correct |
44 |
Execution timed out |
1069 ms |
6512 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |