Asa's CP Library

a01sa01to's competitive programming library.

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub a01sa01to/cp-library

:heavy_check_mark: tests/graph/eulerian-walk/libchecker-undirected.test.cpp

Depends on

Code

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

#include "../../../cpp/library/graph/eulerian-walk.hpp"
#include "../../../cpp/library/data-structure/graph.hpp"
#define PROBLEM "https://judge.yosupo.jp/problem/eulerian_trail_undirected"

void solve() {
  int n, m;
  cin >> n >> m;
  asalib::graph::graph Graph(n);
  rep(_, m) {
    int u, v;
    cin >> u >> v;
    Graph.add_edge(u, v);
  }
  auto res = Graph.eulerian_walk();
  if (!res.has_value()) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
    auto [vs, es] = res.value();
    rep(i, vs.size()) {
      if (i) cout << " ";
      cout << vs[i];
    }
    cout << endl;
    rep(i, es.size()) {
      if (i) cout << " ";
      cout << es[i];
    }
    cout << endl;
  }
}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
Back to top page