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 = 100005; vector
graph[maxn]; vector
bfs(int S) { vector
path; vector
visited(maxn, false); visited[S] = true; queue
q; q.push(S); while(!q.empty()) { int node = q.front(); q.pop(); path.push_back(node); for(int neighbour : graph[node]) { if(!visited[neighbour]) { visited[neighbour] = true; q.push(neighbour); } } } return path; } int main() { int k; cin >> k; for(int i = 1; i < k; i++) { int a, b; cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } vector
p1 = bfs(0); for(int i = 0; i < p1.size(); i++) { cout << p1[i] << " " ; } vector
p2 = bfs(k); for(int i = (int) p2.size() - 1; i >= 0; i--) { cout << p2[i] << " "; } 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)