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;
typedef pair<int, int> pii;
const int MAXN = 1000;
int n, m;
vector<int> edges[MAXN];
int adj[MAXN];
bool vis[MAXN];
bool make_ans(int s, int cur, int msk = 0, int num = 1) {
msk |= (1 << cur);
for (int nxt: edges[cur]) {
if ((1 << nxt) & msk) continue;
if ((adj[nxt] & msk) == (1 << cur)) {
if (make_ans(s, nxt, msk, num+1)) {
cout << (1+cur);
if (cur != s) cout << ' ';
return 1;
}
}
else if ((adj[nxt] & msk) == ((1 << cur) | (1 << s))) {
if (num >= 3) {
cout << (1+nxt) << ' ' << (1+cur) << ' ';
return 1;
}
}
}
return 0;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y; cin >> x >> y;
x--; y--;
edges[x].push_back(y);
edges[y].push_back(x);
adj[x] |= (1 << y);
adj[y] |= (1 << x);
}
for (int i = 0; i < n; i++) {
if (make_ans(i, i)) return 0;
}
cout << "no\n";
}
# | 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... |