Submission #68126213


Source Code Expand

/* Author : goats_9 */

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    cin.tie(0)->sync_with_stdio(false);
    int T;
    cin >> T;
    while (T--) {
        int n, m, x, y;
        cin >> n >> m >> x >> y;
        --x, --y;
        vector<set<int>> g(n);
        for (int i = 0; i < m; i++) {
            int u, v;
            cin >> u >> v;
            g[--u].insert(--v);
            g[v].insert(u);
        }
        vector<int> par(n, -1), vis(n);
        auto dfs = [&] (auto&& self, int u, int p) -> void {
            par[u] = p;
            vis[u] = 1;
            for (auto v : g[u]) {
                if (vis[v]) continue;
                self(self, v, u);
            }
        };
        dfs(dfs, x, -1);
        vector<int> path;
        for (int u = y; u != -1; u = par[u])
            path.push_back(u);
        reverse(path.begin(), path.end());
        for (auto u : path)
            cout << u + 1 << ' ';
        cout << '\n';
    }
    return 0;
}

Submission Info

Submission Time
Task E - A Path in A Dictionary
User goats_9
Language C++ 20 (gcc 12.2)
Score 475
Code Size 1047 Byte
Status AC
Exec Time 29 ms
Memory 8412 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 1
AC × 43
Set Name Test Cases
Sample example_00.txt
All example_00.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3588 KiB
hand_00.txt AC 27 ms 8144 KiB
hand_01.txt AC 1 ms 3768 KiB
hand_02.txt AC 27 ms 8204 KiB
hand_03.txt AC 1 ms 3636 KiB
hand_04.txt AC 15 ms 4116 KiB
hand_05.txt AC 29 ms 8412 KiB
hand_06.txt AC 26 ms 8356 KiB
hand_07.txt AC 1 ms 3648 KiB
hand_08.txt AC 22 ms 7760 KiB
hand_09.txt AC 23 ms 7768 KiB
hand_10.txt AC 2 ms 3836 KiB
hand_11.txt AC 1 ms 3524 KiB
random_00.txt AC 1 ms 3532 KiB
random_01.txt AC 1 ms 3660 KiB
random_02.txt AC 1 ms 3452 KiB
random_03.txt AC 2 ms 3404 KiB
random_04.txt AC 2 ms 3544 KiB
random_05.txt AC 2 ms 3544 KiB
random_06.txt AC 1 ms 3520 KiB
random_07.txt AC 2 ms 3456 KiB
random_08.txt AC 2 ms 3640 KiB
random_09.txt AC 4 ms 3512 KiB
random_10.txt AC 6 ms 3560 KiB
random_11.txt AC 8 ms 3676 KiB
random_12.txt AC 1 ms 3536 KiB
random_13.txt AC 1 ms 3548 KiB
random_14.txt AC 2 ms 3664 KiB
random_15.txt AC 8 ms 3752 KiB
random_16.txt AC 11 ms 4024 KiB
random_17.txt AC 16 ms 4108 KiB
random_18.txt AC 1 ms 3520 KiB
random_19.txt AC 1 ms 3468 KiB
random_20.txt AC 23 ms 7776 KiB
random_21.txt AC 3 ms 4044 KiB
random_22.txt AC 25 ms 7264 KiB
random_23.txt AC 27 ms 8136 KiB
random_24.txt AC 1 ms 3588 KiB
random_25.txt AC 1 ms 3720 KiB
random_26.txt AC 26 ms 8216 KiB
random_27.txt AC 26 ms 8236 KiB
random_28.txt AC 27 ms 8304 KiB
random_29.txt AC 26 ms 8236 KiB