Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
#include
#include
#include
#define ll long long #define ps push_back using namespace std; const int maxn = 1e5 + 10; vector
graph[maxn]; bool visited[maxn]; vector
cycle; bool dfs(int node, int parent) { visited[node] = true; for(int i = 0; i < (int) graph[node].size(); i++) { int neighbour = graph[node][i]; cycle.push_back(neighbour); if(!visited[neighbour]) { if(dfs(neighbour, node)) { return true; } } else if(neighbour != parent) { return true; } cycle.pop_back(); } return false; } int main() { int n,m; cin >>n >> m; for(int i = 0;i
> a >> b; graph[a].push_back(b); graph[b].push_back(a); } memset(visited, false, sizeof visited); for(int i = 1; i <= n; i++) { cycle.push_back(i); if(!visited[i] and dfs(i, -1)) { vector
res; for(int j = (int) cycle.size() - 1; j >= 0; j--) { res.push_back(cycle[j]); if(cycle[j] == cycle[(int) cycle.size() - 1] and j != (int) cycle.size() - 1 ) { break; } } cout << res.size() << endl; for(int x : res) { cout << x << " " ; } return 0; } cycle.pop_back(); } cout << "IMPOSSIBLE" << endl; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)