Submission #1075037

#TimeUsernameProblemLanguageResultExecution timeMemory
1075037OspleiSenior Postmen (BOI14_postmen)C++17
0 / 100
7 ms12380 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef pair<int,int> ii;
typedef int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii; 
typedef vector<vii> wgraf;
typedef pair<int,ii> edge;
typedef vector <ll> vl;
typedef pair <ll, ll> LL;
typedef vector <LL> vll;
 
#define UNVISITED 0
#define VISITED 1
#define pb push_back
#define F first
#define S second
 
ll n, m, u, v, visto[500005], cone[500005];
vll grafo[500005];
bool vale = false, puede[500005], volver = false;

void dfs(ll origen, ll nodo, ll aux) {

  if (visto[nodo] == aux) {
    origen = nodo;
    vale = true;
    return;
  }

  visto[nodo] = aux;
  
  for (auto i : grafo[nodo]) {

    if (puede[i.S] == true) {
    
      puede[i.S] = false;

      if (volver == false) dfs(origen, i.F, aux);

      if (vale == true) {
      
        if (nodo == origen) {
          vale = false;
          volver = true;
        }
        
        cout << nodo << " ";
        return;
      
      }

      puede[i.S] = true;
    
    }
    
  }

}
 
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  
  cin >> n >> m;

  for (ll i = 0; i < n; i++) visto[i] = -1;

  for (ll i = 0; i < m; i++){
    cin >> u >> v;

    grafo[u].pb({v, i});
    grafo[v].pb({u, i});

    puede[i] = true;
    cone[i] = u;
  }

  ll cnt = 0;

  for (ll i = 0; i < m; i++) {
    if (puede[i] == true) {
      vale = false;
      volver = false;
      cnt++;
      dfs(-1, cone[i], cnt);
      cout << "\n";
    }
  }

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...