#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<int> al[MAXN], g[MAXN];
bool conn[MAXN][MAXN];
int E, from[2*MAXR], to[2*MAXR], vis[2*MAXR], pa[2*MAXR];
void bfs(int s) {
queue<int> q;
FOR(i,0,E-1) pa[i] = -1;
q.push(s);
//cout << "S " << from[s] << " " << to[s] << endl;
while (!q.empty()) {
int u = q.front(); q.pop();
//cout << "U " << from[u] << " " << to[u] << endl;
for (int v : g[u]) {
//cout << "\t\tV " << from[v] << " " << to[v] << endl;
if (v == s) {
//cout << "ANS" << '\n';
//vector<int> edges;
//for (int e = u; e != -1; e = pa[e]) edges.push_back(e);
//for (auto& e : edges) { cout << from[e] << " " << to[e] << " :: "; } cout << endl;
for (int e = u; e != -1; e = pa[e]) cout << to[e] << (pa[e]==-1?'\n':' ');
exit(0);
} else if (pa[v] == -1) pa[v] = u, q.push(v);
}
}
}
void dfs(int u) {
vis[u] = 2;
for (int v : g[u]) {
if (vis[v] == 2) {
bfs(v); // ans
} else if (!vis[v]) dfs(v);
}
vis[u] = 1;
}
int main() {
//freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> R; E = 0;
FOR(i,1,R){
int A, B; cin >> A >> B;
from[E] = A, to[E] = B;
al[A].push_back(E++);
from[E] = B, to[E] = A;
al[B].push_back(E++);
conn[A][B] = conn[B][A] = 1;
}
FOR(i,1,N) FOR(j,0,SZ(al[i])-1) { // + ^ O(E)
FOR(k,j+1,SZ(al[i])-1) { // O(N)
int e = al[i][j], f = al[i][k];
if (!conn[to[e]][to[f]]) g[e^1].push_back(f), g[f^1].push_back(e);
}
}
FOR(i,0,E-1) vis[i] = 0;
FOR(i,0,E-1) if (!vis[i]) dfs(i);
cout << "no" << '\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 |
376 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 |
Runtime error |
6 ms |
1076 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
1400 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
1400 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
19 ms |
5596 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
3960 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
31 ms |
7200 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |