답안 #154051

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
154051 2019-09-18T02:14:35 Z gratus907 두 로봇 (KOI18_robot) C++17
59 / 100
1000 ms 9080 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#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()
{
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 164 ms 8440 KB Output is correct
2 Correct 153 ms 7416 KB Output is correct
3 Correct 144 ms 7344 KB Output is correct
4 Correct 5 ms 2808 KB Output is correct
5 Correct 22 ms 3320 KB Output is correct
6 Correct 26 ms 3576 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 34 ms 3704 KB Output is correct
9 Correct 8 ms 2808 KB Output is correct
10 Correct 38 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 49 ms 4216 KB Output is correct
14 Correct 54 ms 4708 KB Output is correct
15 Correct 10 ms 2936 KB Output is correct
16 Correct 71 ms 5112 KB Output is correct
17 Correct 72 ms 5544 KB Output is correct
18 Correct 89 ms 5848 KB Output is correct
19 Correct 13 ms 2936 KB Output is correct
20 Correct 93 ms 6264 KB Output is correct
21 Correct 116 ms 6644 KB Output is correct
22 Correct 119 ms 6864 KB Output is correct
23 Correct 16 ms 3068 KB Output is correct
24 Correct 139 ms 7288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 175 ms 8924 KB Output is correct
2 Correct 143 ms 7320 KB Output is correct
3 Correct 5 ms 2680 KB Output is correct
4 Correct 5 ms 2808 KB Output is correct
5 Correct 28 ms 3704 KB Output is correct
6 Correct 26 ms 3576 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 42 ms 3960 KB Output is correct
9 Correct 123 ms 4160 KB Output is correct
10 Correct 4 ms 2680 KB Output is correct
11 Correct 55 ms 4676 KB Output is correct
12 Correct 65 ms 4728 KB Output is correct
13 Correct 10 ms 2808 KB Output is correct
14 Correct 11 ms 2936 KB Output is correct
15 Correct 94 ms 5724 KB Output is correct
16 Correct 75 ms 5496 KB Output is correct
17 Correct 99 ms 6172 KB Output is correct
18 Correct 580 ms 6512 KB Output is correct
19 Correct 121 ms 6840 KB Output is correct
20 Correct 135 ms 7160 KB Output is correct
21 Correct 16 ms 3064 KB Output is correct
22 Correct 16 ms 3192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2812 KB Output is correct
2 Correct 6 ms 2808 KB Output is correct
3 Correct 6 ms 2808 KB Output is correct
4 Correct 4 ms 2812 KB Output is correct
5 Correct 7 ms 2936 KB Output is correct
6 Correct 7 ms 2808 KB Output is correct
7 Correct 10 ms 2936 KB Output is correct
8 Correct 5 ms 2808 KB Output is correct
9 Correct 4 ms 2768 KB Output is correct
10 Correct 9 ms 2936 KB Output is correct
11 Correct 9 ms 2936 KB Output is correct
12 Correct 10 ms 2940 KB Output is correct
13 Correct 13 ms 2936 KB Output is correct
14 Correct 11 ms 2936 KB Output is correct
15 Correct 12 ms 3064 KB Output is correct
16 Correct 5 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 193 ms 9080 KB Output is correct
2 Correct 180 ms 8984 KB Output is correct
3 Correct 155 ms 8472 KB Output is correct
4 Correct 152 ms 7364 KB Output is correct
5 Correct 144 ms 7356 KB Output is correct
6 Correct 195 ms 8444 KB Output is correct
7 Correct 6 ms 2680 KB Output is correct
8 Correct 5 ms 2808 KB Output is correct
9 Correct 6 ms 2808 KB Output is correct
10 Correct 22 ms 3320 KB Output is correct
11 Correct 6 ms 2808 KB Output is correct
12 Correct 30 ms 3744 KB Output is correct
13 Correct 27 ms 3704 KB Output is correct
14 Correct 26 ms 3576 KB Output is correct
15 Correct 4 ms 2680 KB Output is correct
16 Correct 7 ms 2808 KB Output is correct
17 Correct 34 ms 3668 KB Output is correct
18 Correct 7 ms 2808 KB Output is correct
19 Correct 38 ms 3960 KB Output is correct
20 Correct 88 ms 4208 KB Output is correct
21 Correct 117 ms 4084 KB Output is correct
22 Correct 10 ms 2808 KB Output is correct
23 Correct 4 ms 2680 KB Output is correct
24 Correct 4 ms 2680 KB Output is correct
25 Correct 9 ms 2908 KB Output is correct
26 Correct 49 ms 4216 KB Output is correct
27 Correct 9 ms 2936 KB Output is correct
28 Correct 54 ms 4728 KB Output is correct
29 Correct 64 ms 4728 KB Output is correct
30 Correct 59 ms 4696 KB Output is correct
31 Correct 9 ms 2936 KB Output is correct
32 Correct 13 ms 2936 KB Output is correct
33 Correct 10 ms 2936 KB Output is correct
34 Correct 69 ms 4900 KB Output is correct
35 Correct 11 ms 2908 KB Output is correct
36 Correct 88 ms 5764 KB Output is correct
37 Correct 82 ms 5704 KB Output is correct
38 Correct 73 ms 5496 KB Output is correct
39 Correct 12 ms 3068 KB Output is correct
40 Correct 5 ms 2680 KB Output is correct
41 Correct 92 ms 5748 KB Output is correct
42 Correct 13 ms 3044 KB Output is correct
43 Correct 94 ms 6136 KB Output is correct
44 Execution timed out 1071 ms 6632 KB Time limit exceeded
45 Halted 0 ms 0 KB -