#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)
const int MAXN = 1e3+5;
const int MAXR = 1e5+5;
int N, R;
vector<ii> el;
vector<int> al[MAXN];
bool conn[MAXN][MAXN];
int pa[MAXN];
vector<int> ans;
void solve(int s) {
for (auto v : al[s]) {
queue<int> q;
FOR(i,1,N) pa[i] = -1;
pa[v] = 0; q.push(v);
while (!q.empty()) {
int u = q.front(); q.pop();
if (u == v || !conn[u][s]) for (int w : al[u]) if (w != s and pa[w] == -1) pa[w] = u, q.push(w);
}
FOR(i,1,N) if (i != v and pa[i] != -1 and !conn[v][i] and conn[s][i]) {
//cout << "FOUND " << v << " " << s << " " << i << endl;
ans.push_back(s);
for (int w = i; w != 0; w = pa[w]) ans.push_back(w);
assert(SZ(ans) > 3);
return;
}
}
}
int main() {
//freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> R;
FOR(i,1,R){
int A, B; cin >> A >> B;
al[A].push_back(B);
al[B].push_back(A);
el.emplace_back(A,B);
conn[A][B] = conn[B][A] = 1;
}
FOR(i,1,N) if (ans.empty()) { solve(i); } else break;
if (ans.empty()) cout << "no" << '\n';
else FOR(i,0,SZ(ans)-1) cout << ans[i] << (i<SZ(ans)-1?' ':'\n');
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
7 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
816 KB |
Output is correct |
2 |
Correct |
4 ms |
760 KB |
Output is correct |
3 |
Correct |
6 ms |
888 KB |
Output is correct |
4 |
Correct |
108 ms |
892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
760 KB |
Output is correct |
2 |
Correct |
51 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
2704 KB |
Output is correct |
2 |
Correct |
27 ms |
2040 KB |
Output is correct |
3 |
Execution timed out |
1076 ms |
2676 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
2040 KB |
Output is correct |
2 |
Execution timed out |
1071 ms |
2016 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
3312 KB |
Output is correct |
2 |
Correct |
832 ms |
3184 KB |
Output is correct |
3 |
Correct |
270 ms |
3184 KB |
Output is correct |
4 |
Execution timed out |
1072 ms |
3184 KB |
Time limit exceeded |