Submission #68157951


Source Code Expand

#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i, a, b) for (int i = (a); i <= int(b); i++)

#if __has_include("shik/dump.h")
#include "shik/dump.h"
#else
#define dump(...) 0
#endif

using namespace std;

const int N = 1010;

int n, m, x, y;
vector<int> e[N];
void input() {
  cin >> n >> m >> x >> y;
  for (int i = 1; i <= n; i++) e[i].clear();
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    e[u].push_back(v);
    e[v].push_back(u);
  }
}

vector<int> path;
bool vis[N];
bool dfs(int u) {
  vis[u] = true;
  path.push_back(u);
  if (u == y) {
    return true;
  }
  for (int v : e[u]) {
    if (vis[v]) continue;
    if (dfs(v)) return true;
  }
  path.pop_back();
  return false;
}

void solve() {
  for (int i = 1; i <= n; i++) {
    sort(ALL(e[i]));
    vis[i] = false;
  }
  path.clear();
  dfs(x);
  for (int i = 0; i < SZ(path); i++) {
    if (i) cout << " ";
    cout << path[i];
  }
  cout << "\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int num_cases = 0;
  cin >> num_cases;
  REP1(i, 1, num_cases) {
    input();
    solve();
  }
}

Submission Info

Submission Time
Task E - A Path in A Dictionary
User shik
Language C++ 23 (gcc 12.2)
Score 475
Code Size 1273 Byte
Status AC
Exec Time 8 ms
Memory 4224 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 3412 KiB
hand_00.txt AC 8 ms 4028 KiB
hand_01.txt AC 1 ms 3548 KiB
hand_02.txt AC 8 ms 3908 KiB
hand_03.txt AC 1 ms 3456 KiB
hand_04.txt AC 6 ms 3484 KiB
hand_05.txt AC 8 ms 4204 KiB
hand_06.txt AC 7 ms 4224 KiB
hand_07.txt AC 1 ms 3488 KiB
hand_08.txt AC 7 ms 4132 KiB
hand_09.txt AC 7 ms 4164 KiB
hand_10.txt AC 1 ms 3716 KiB
hand_11.txt AC 1 ms 3480 KiB
random_00.txt AC 1 ms 3492 KiB
random_01.txt AC 1 ms 3460 KiB
random_02.txt AC 1 ms 3624 KiB
random_03.txt AC 1 ms 3484 KiB
random_04.txt AC 1 ms 3492 KiB
random_05.txt AC 1 ms 3432 KiB
random_06.txt AC 1 ms 3480 KiB
random_07.txt AC 1 ms 3432 KiB
random_08.txt AC 1 ms 3440 KiB
random_09.txt AC 2 ms 3428 KiB
random_10.txt AC 3 ms 3460 KiB
random_11.txt AC 3 ms 3368 KiB
random_12.txt AC 1 ms 3412 KiB
random_13.txt AC 1 ms 3632 KiB
random_14.txt AC 1 ms 3508 KiB
random_15.txt AC 3 ms 3528 KiB
random_16.txt AC 5 ms 3576 KiB
random_17.txt AC 6 ms 3580 KiB
random_18.txt AC 1 ms 3460 KiB
random_19.txt AC 1 ms 3484 KiB
random_20.txt AC 7 ms 4120 KiB
random_21.txt AC 2 ms 3580 KiB
random_22.txt AC 8 ms 3908 KiB
random_23.txt AC 8 ms 4044 KiB
random_24.txt AC 1 ms 3536 KiB
random_25.txt AC 1 ms 3568 KiB
random_26.txt AC 7 ms 4012 KiB
random_27.txt AC 8 ms 4076 KiB
random_28.txt AC 8 ms 4112 KiB
random_29.txt AC 8 ms 4184 KiB