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
using namespace std; const int maxn = 1e5 + 5; int n, m; vector
graph[maxn]; vector
bfs(int S, int E) { queue
q; q.push(S); q.push(0); vector
visited(n + 1, false); visited[S] = true; vector
path(n, -1); while(!q.empty()) { int node = q.front(); q.pop(); int dist = q.front(); q.pop(); for(int neighbour : graph[node]) { if(!visited[neighbour]) { visited[neighbour] = true; q.push(neighbour); q.push(dist + 1); path[neighbour] = node; } } } return path; } int main() { ios_base::sync_with_stdio(false); cin >> n >> m; for(int i = 0; i < m; i++) { int a, b; cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } int S, E; cin >> S >> E; vector
p = bfs(S, E); while(E != S) { cout << E << " "; E = p[E]; } cout << S << endl; return 0; }
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)