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>
using namespace std;
const int mxN = 1005, mxM = 2e5 + 5;
int n, m, u[mxM], v[mxM], adj1[mxN][mxN]; vector<int> adj2[mxM], stk; bool vis[mxM], active[mxM];
void dfs(int cur, int p){
vis[cur] = active[cur] = 1; stk.push_back(cur);
for (int nxt : adj2[cur]) if (nxt != p and active[nxt]){
while (stk.back() != nxt){
cout<<u[stk.back()]<<" ";
stk.pop_back();
}
cout<<u[stk.back()]<<endl;
exit(0);
}
for (int nxt : adj2[cur]) if (nxt != p and !vis[nxt]) dfs(nxt, cur);
active[cur] = 0; stk.pop_back();
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; i++){
int a, b; cin >> a >> b;
u[i * 2] = a; v[i * 2] = b;
u[i * 2 + 1] = b; v[i * 2 + 1] = a;
adj1[a][b] = i * 2; adj1[b][a] = i * 2 + 1;
}
for (int i = 1; i <= 2 * m; i++)
for (int j = 1; j <= n; j++)
if (adj1[v[i]][j] and j != u[i])
if (!adj1[u[i]][j])
adj2[i].push_back(adj1[v[i]][j]);
for (int i = 1; i <= 2 * m; i++) if (!vis[i]) dfs(i, 0);
cout<<"no"<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |