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>
typedef long long ll;
using namespace std;
const int maxn = 1e3 + 5;
vector<int> g[maxn];
int e[maxn][maxn], vis[maxn], p[maxn];
void dfs(int u, int s, vector<int> &st)
{
vis[u] = true;
if (e[u][s])
{
st.push_back(u);
return;
}
for (int v : g[u]) if (!vis[v]) dfs(v, s, st);
}
void bfs(int s, int u1, int u2)
{
memset(p, -1, sizeof(p));
queue<int> q;
q.push(u1);
p[s] = p[u1] = s;
while (!q.empty())
{
int v = q.front(); q.pop();
for (int i : g[v]) if (p[i] == -1 && (i == u2 || !e[i][s]))
{
q.push(i);
p[i] = v;
}
}
int vr = u2;
while (p[vr] != vr)
{
cout << vr + 1 << " ";
vr = p[vr];
}
cout << s + 1 << endl;
exit(0);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, r;
cin >> n >> r;
for (int i = 0, a, b; i < r; i++)
{
cin >> a >> b;
g[--a].push_back(--b), g[b].push_back(a);
e[a][b] = e[b][a] = true;
}
for (int i = 0; i < n; i++) e[i][i] = true;
for (int i = 0; i < n; i++)
{
memset(vis, 0, sizeof(vis));
for (int j = 0; j < n; j++) if (!vis[j] && !e[i][j])
{
vector<int> v;
dfs(j, i, v);
for (int u : v) vis[u] = false;
for (int u1 : v) for (int u2 : v) if (!e[u1][u2])
bfs(i, u1, u2);
}
}
cout << "no\n";
return 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... |
# | 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... |