#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int n,m;
vector<int> adj[1010];
int depth[1010],p[1010];
int relabel[1010];
int counter;
int visited[1010];
int rmap[1010];
void dfs(int u,int pa){
visited[u] = 1;
//cout << u << pa << "hi\n";
for (int i = 0; i < adj[u].size(); i++){
int v = adj[u][i];
if (!visited[v]){
p[v] = u;
depth[v] = depth[u]+1;
visited[v] = 1;
dfs(v,u);
}
}
relabel[u] = ++counter;
rmap[relabel[u]] = u;
}
vector<int> lowestjump[1010];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++){
int x,y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
for (int i = 1; i <= n; i++){
if (!visited[i]){
depth[i] = 1;
p[i] = -1;
dfs(i,-1);
}
}
vector<ii> backedges;
for (int i = 1; i <= n; i++){
if (p[i] != -1) assert(relabel[p[i]] > relabel[i]);
for (int j = 0; j < adj[i].size(); j++){
int ni = adj[i][j];
if (p[ni] == i || p[i] == ni) continue;
if (depth[i] < depth[ni]) continue;
lowestjump[i].push_back(relabel[ni]);
if (depth[i]-depth[ni] >= 3) backedges.push_back(ii(i,ni));
}
lowestjump[i].push_back(relabel[p[i]]);
sort(lowestjump[i].begin(),lowestjump[i].end());
}
for (int i = 0; i < backedges.size(); i++){
int minjump = 1e9;
int start = backedges[i].first, fin = backedges[i].second;
//cout << start << " " << fin << "\n";
int counter = 1;
int cur = start;
vector<int> temp;
temp.push_back(cur);
while (relabel[cur] < relabel[fin]){
int relabelval = *(upper_bound(lowestjump[cur].begin(),lowestjump[cur].end(),relabel[fin])-1);
if (cur == start) relabelval = *(lower_bound(lowestjump[cur].begin(),lowestjump[cur].end(),relabel[fin])-1);
int pos = rmap[relabelval];
cur = pos;
temp.push_back(cur);
//start++;
}
if (cur != fin || temp.size() < 4) continue;
for (int j = 0; j < temp.size(); j++) cout <<temp[j] << " ";
return 0;
}
cout << "no";
return 0;
}
Compilation message
indcyc.cpp: In function 'void dfs(int, int)':
indcyc.cpp:14:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < adj[u].size(); i++){
~~^~~~~~~~~~~~~~~
indcyc.cpp: In function 'int main()':
indcyc.cpp:47:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < adj[i].size(); j++){
~~^~~~~~~~~~~~~~~
indcyc.cpp:57:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < backedges.size(); i++){
~~^~~~~~~~~~~~~~~~~~
indcyc.cpp:74:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < temp.size(); j++) cout <<temp[j] << " ";
~~^~~~~~~~~~~~~
indcyc.cpp:58:13: warning: unused variable 'minjump' [-Wunused-variable]
int minjump = 1e9;
^~~~~~~
indcyc.cpp:61:13: warning: unused variable 'counter' [-Wunused-variable]
int counter = 1;
^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
6 ms |
640 KB |
Output is correct |
4 |
Correct |
7 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
512 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1728 KB |
Output is correct |
2 |
Correct |
12 ms |
1280 KB |
Output is correct |
3 |
Correct |
25 ms |
2080 KB |
Output is correct |
4 |
Correct |
13 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
1024 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
2804 KB |
Output is correct |
2 |
Correct |
48 ms |
2680 KB |
Output is correct |
3 |
Correct |
28 ms |
2040 KB |
Output is correct |
4 |
Correct |
34 ms |
2552 KB |
Output is correct |