Submission #1203721

#TimeUsernameProblemLanguageResultExecution timeMemory
1203721repmann어르신 집배원 (BOI14_postmen)C++20
0 / 100
143 ms327680 KiB
#include <bits/stdc++.h>
using namespace std;
int N, M;
bool D[500096], V[500096];
stack <pair <int, int>> VG[500096];
inline void Euler()
{
  int node = 1, temp;
  stack <int> S, T;
  S.push(node);
  while(S.size())
  {
    node = S.top();
    while(VG[node].size() && V[VG[node].top().first]) VG[node].pop();
    if(VG[node].size())
    {
      V[VG[node].top().first] = true;
      temp = VG[node].top().second;
      VG[node].pop();
      S.push(temp);
      continue;
    }
    if(D[node])
    {
      while(D[node]) {cout << T.top() << ' '; D[T.top()] = false; T.pop();}
      cout << '\n';
    }
    T.push(node); D[node] = true;
    S.pop();
  }
  return;
}
int main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> N >> M;
  int u, v;
  for(int i = 1; i <= M; i++)
  {
    cin >> u >> v;
    VG[u].push({i, v});
    VG[v].push({i, u});
  }
  Euler();

  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...