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 FOR(i, a, b) for (int i = a; i<= b; ++i)
#define FORD(i, a, b) for (int i = a; i>=b; --i)
#define REP(i, a) for (int i = 0; i<a; ++i)
#define DEBUG(x) { cerr << #x << " = " << x << endl; }
#define Arr(A, l, r) { cerr << #A << " = "; FOR(_, l, r) cerr << A[_] << ' '; cerr << endl; }
#define N 1111
#define pp pair<int, int>
#define next __next
#define prev __prev
#define __builtin_popcount __builtin_popcountll
#define bit(S, i) (((S) >> i) & 1)
#define IO cin.tie(NULL);cout.tie(NULL);
#define taskname "Test"
using namespace std;
int n, m, p[N];
vector<int> e[N];
queue<int> q;
bitset<N> banned[N], parent[N];
void Try(int s) {
while (!q.empty()) q.pop();
FOR(i, 1, n) {
p[i] = 0;
banned[i].reset();
parent[i].reset();
}
q.push(s);
parent[s].set(s);
p[s] = -1;
while (!q.empty()) {
int u = q.front();q.pop();
for (int v : e[u]) if (v != p[u]) {
if (p[v] == 0) {
}
else {
if ((parent[u] & parent[v]).count() > 1) continue;
// FOR(i, 1, n) if (banned[v][i]) cerr << i << ' '; cerr << endl;
// FOR(i, 1, n) if (parent[u][i]) cerr << i << ' '; cerr << endl;
if (parent[u].count() + parent[v].count() > 4 && (banned[v] & parent[u]).count() == 0) {
vector<int> res;
int t = u;
while (t != s) {
res.push_back(t);
t = p[t];
}
while (!res.empty()) cout << res.back() << ' ',res.pop_back();
t = v;
while (t != -1) {
cout << t << ' ';
t = p[t];
}
exit(0);
}
banned[u].set(v);
banned[v].set(u);
}
}
for (int v : e[u]) if (v != p[u]) {
if (p[v] == 0) {
p[v] = u;
banned[v] = banned[u];
parent[v] = parent[u];
parent[v].set(v);
q.push(v);
}
}
}
}
int main() {
IO;ios::sync_with_stdio(false);
cin >> n >> m;
REP(i, m) {
int u, v;
cin >> u >> v;
e[u].push_back(v);
e[v].push_back(u);
}
FOR(i, 1, n) Try(i);
cout << "no";
}
# | 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... |