#include <bits/stdc++.h>
#define MP make_pair
#define F first
#define PB push_back
#define S second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int maxn = 1e3 + 4;
vector <int> adj[maxn];
int mat[maxn][maxn];
int par[maxn];
void find_path (int v, int u, int w) {
queue <int> q;
memset (par, -1, sizeof par);
q.push (v);
par[v] = 0;
while (!q.empty()) {
int x = q.front();
q.pop();
for (auto y : adj[x]) {
if (par[y] == -1 and y != u) {
par[y] = x;
q.push(y);
}
}
}
while (w != 0) {
cout << w << " ";
w = par[w];
}
cout << u << endl;
exit(0);
}
int get(int v) {
if (par[v] == -1)
return v;
return par[v] = get(par[v]);
}
void merge(int v, int u) {
v = get(v), u = get(u);
if (v == u)
return;
par[v] = u;
}
bool mark[maxn];
pii e[100005];
int main (){
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int v, u;
cin >> v >> u;
e[i] = {v, u};
adj[v].PB(u);
adj[u].PB(v);
mat[v][u] = 1;
mat[u][v] = 1;
}
for (int i = 1; i <= n; i++) {
memset (par, -1, sizeof par);
for (auto v : adj[i]) {
mark[v] = 1;
}
for (int j = 0; j < m; j++) {
if (e[j].F != i and e[j].S != i and (!mark[e[j].F] or !mark[e[j].S])) {
merge (e[j].F, e[j].S);
}
}
for (int j = 0; j < adj[i].size(); j++) {
for (int k = j + 1; k < adj[i].size(); k++) {
int v = adj[i][j], u = adj[i][k];
if (!mat[v][u] and get(v) == get(u))
find_path (v, i, u);
}
}
for (auto v : adj[i]) {
mark[v] = 0;
}
}
cout << "no" << endl;
}
Compilation message
indcyc.cpp: In function 'int main()':
indcyc.cpp:79:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < adj[i].size(); j++) {
~~^~~~~~~~~~~~~~~
indcyc.cpp:80:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k = j + 1; k < adj[i].size(); k++) {
~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
540 KB |
Output is correct |
3 |
Correct |
3 ms |
540 KB |
Output is correct |
4 |
Correct |
2 ms |
548 KB |
Output is correct |
5 |
Correct |
2 ms |
548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
776 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
1016 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
1932 KB |
Output is correct |
2 |
Incorrect |
4 ms |
1932 KB |
Wrong adjacency |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
1932 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
5392 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
5392 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
49 ms |
5392 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |