Submission #544674

# Submission time Handle Problem Language Result Execution time Memory
544674 2022-04-02T14:20:42 Z pokmui9909 None (KOI18_robot) C++17
100 / 100
114 ms 13180 KB
#include <bits/stdc++.h>
using namespace std;

vector<pair<int, int>> tree[100005];
int cost1[100005], cost2[100005];
int visited[100005];
int n, x, y;

void dfs1(int node, int c)
{
    visited[node] = 1;
    cost1[node] = c;
    for(int i = 0; i < tree[node].size(); i++)
    {
        int next = tree[node][i].first;
        if(visited[next]) continue;
        dfs1(next, c + tree[node][i].second);
    }
}

void dfs2(int node, int c)
{
    visited[node] = 1;
    cost2[node] = c;
    for(int i = 0; i < tree[node].size(); i++)
    {
        int next = tree[node][i].first;
        if(visited[next]) continue;
        dfs2(next, c + tree[node][i].second);
    }
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(false);

    cin >> n >> x >> y;
    if(x == y)
    {
        cout << 0;
        return 0;
    }
    for(int i = 1; i <= n - 1; i++)
    {
        int a, b, c; cin >> a >> b >> c;
        tree[a].push_back({b, c});
        tree[b].push_back({a, c});
    }
    dfs1(x, 0);
    for(int i = 1; i <= n; i++)
        visited[i] = 0;
    dfs2(y, 0);
    //for(int i = 1; i <= n; i++)
        //cout << cost1[i] << ' ';
    int ans = INT_MAX;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j < tree[i].size(); j++)
        {
            ans = min(ans, cost1[i] + cost2[tree[i][j].first]);
        }
    }
    cout << ans;
}

Compilation message

robot.cpp: In function 'void dfs1(int, int)':
robot.cpp:13:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int i = 0; i < tree[node].size(); i++)
      |                    ~~^~~~~~~~~~~~~~~~~~~
robot.cpp: In function 'void dfs2(int, int)':
robot.cpp:25:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i = 0; i < tree[node].size(); i++)
      |                    ~~^~~~~~~~~~~~~~~~~~~
robot.cpp: In function 'int main()':
robot.cpp:59:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for(int j = 0; j < tree[i].size(); j++)
      |                        ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 45 ms 13136 KB Output is correct
2 Correct 2 ms 2692 KB Output is correct
3 Correct 57 ms 11244 KB Output is correct
4 Correct 2 ms 2780 KB Output is correct
5 Correct 7 ms 3844 KB Output is correct
6 Correct 8 ms 4060 KB Output is correct
7 Correct 3 ms 2644 KB Output is correct
8 Correct 10 ms 4624 KB Output is correct
9 Correct 3 ms 2900 KB Output is correct
10 Correct 11 ms 5080 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2676 KB Output is correct
13 Correct 14 ms 5792 KB Output is correct
14 Correct 15 ms 6220 KB Output is correct
15 Correct 3 ms 3028 KB Output is correct
16 Correct 18 ms 6652 KB Output is correct
17 Correct 20 ms 7664 KB Output is correct
18 Correct 48 ms 8140 KB Output is correct
19 Correct 5 ms 3208 KB Output is correct
20 Correct 27 ms 8268 KB Output is correct
21 Correct 31 ms 9756 KB Output is correct
22 Correct 31 ms 10524 KB Output is correct
23 Correct 9 ms 3328 KB Output is correct
24 Correct 37 ms 10360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 9504 KB Output is correct
2 Correct 49 ms 11224 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 3 ms 2688 KB Output is correct
5 Correct 14 ms 3668 KB Output is correct
6 Correct 8 ms 4040 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 11 ms 5180 KB Output is correct
9 Correct 17 ms 4176 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 16 ms 6172 KB Output is correct
12 Correct 20 ms 4876 KB Output is correct
13 Correct 3 ms 3028 KB Output is correct
14 Correct 4 ms 2900 KB Output is correct
15 Correct 33 ms 5992 KB Output is correct
16 Correct 29 ms 7656 KB Output is correct
17 Correct 25 ms 8320 KB Output is correct
18 Correct 28 ms 6800 KB Output is correct
19 Correct 33 ms 10572 KB Output is correct
20 Correct 46 ms 7680 KB Output is correct
21 Correct 5 ms 3368 KB Output is correct
22 Correct 6 ms 3208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2772 KB Output is correct
2 Correct 3 ms 2688 KB Output is correct
3 Correct 3 ms 2772 KB Output is correct
4 Correct 2 ms 2680 KB Output is correct
5 Correct 3 ms 2772 KB Output is correct
6 Correct 4 ms 2816 KB Output is correct
7 Correct 3 ms 2820 KB Output is correct
8 Correct 3 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 3 ms 2772 KB Output is correct
11 Correct 4 ms 2900 KB Output is correct
12 Correct 5 ms 3028 KB Output is correct
13 Correct 4 ms 2900 KB Output is correct
14 Correct 6 ms 2952 KB Output is correct
15 Correct 4 ms 3028 KB Output is correct
16 Correct 2 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 9692 KB Output is correct
2 Correct 112 ms 9512 KB Output is correct
3 Correct 46 ms 13156 KB Output is correct
4 Correct 3 ms 2692 KB Output is correct
5 Correct 49 ms 11316 KB Output is correct
6 Correct 107 ms 13180 KB Output is correct
7 Correct 5 ms 2644 KB Output is correct
8 Correct 2 ms 2684 KB Output is correct
9 Correct 3 ms 2688 KB Output is correct
10 Correct 7 ms 3844 KB Output is correct
11 Correct 3 ms 2772 KB Output is correct
12 Correct 10 ms 3712 KB Output is correct
13 Correct 10 ms 3708 KB Output is correct
14 Correct 8 ms 4052 KB Output is correct
15 Correct 3 ms 2644 KB Output is correct
16 Correct 3 ms 2772 KB Output is correct
17 Correct 13 ms 4612 KB Output is correct
18 Correct 4 ms 2868 KB Output is correct
19 Correct 11 ms 5120 KB Output is correct
20 Correct 17 ms 4232 KB Output is correct
21 Correct 10 ms 4176 KB Output is correct
22 Correct 4 ms 2836 KB Output is correct
23 Correct 2 ms 2680 KB Output is correct
24 Correct 3 ms 2644 KB Output is correct
25 Correct 4 ms 2772 KB Output is correct
26 Correct 14 ms 5716 KB Output is correct
27 Correct 5 ms 2816 KB Output is correct
28 Correct 21 ms 6228 KB Output is correct
29 Correct 25 ms 4996 KB Output is correct
30 Correct 23 ms 4816 KB Output is correct
31 Correct 3 ms 3028 KB Output is correct
32 Correct 6 ms 2900 KB Output is correct
33 Correct 3 ms 2900 KB Output is correct
34 Correct 24 ms 6532 KB Output is correct
35 Correct 5 ms 2900 KB Output is correct
36 Correct 53 ms 6084 KB Output is correct
37 Correct 36 ms 5908 KB Output is correct
38 Correct 24 ms 7652 KB Output is correct
39 Correct 7 ms 3028 KB Output is correct
40 Correct 2 ms 2644 KB Output is correct
41 Correct 35 ms 8084 KB Output is correct
42 Correct 6 ms 3204 KB Output is correct
43 Correct 31 ms 8352 KB Output is correct
44 Correct 42 ms 6896 KB Output is correct
45 Correct 34 ms 6780 KB Output is correct
46 Correct 36 ms 9676 KB Output is correct
47 Correct 38 ms 10576 KB Output is correct
48 Correct 78 ms 7852 KB Output is correct
49 Correct 70 ms 7684 KB Output is correct
50 Correct 5 ms 3412 KB Output is correct
51 Correct 6 ms 3204 KB Output is correct
52 Correct 6 ms 3204 KB Output is correct
53 Correct 39 ms 10432 KB Output is correct