This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define fi first
#define se second
#define INF 1e7
#define unsigned u
#define eps 1e-18
#define eps1 1e-25
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MAX_A 100005
#define V 450
using namespace std;
const int maxn = 5e5 + 5;
vii adj[maxn];
bool vis[maxn], tv[maxn];
int parent[maxn];
void dfs(int u){
if(tv[u]){
while(tv[u]){
cout << u+1 << " ";
tv[u] = 0;
u = parent[u];
}
cout << "\n";
}
while(!adj[u].empty()){
ii x =adj[u].back();
adj[u].pop_back();
if(!vis[x.se]){
vis[x.se] = 1;
tv[u] = 1;
parent[u] = x.fi;
dfs(x.fi);
}
}
}
int main(){
optimise;
int n,m,a,b;
cin >> n >> m;
for (int i = 0; i < m; ++i)
{
cin >> a >>b;
a--,b--;
adj[a].pb({b,i});
adj[b].pb({a,i});
}
dfs(0);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |