제출 #648047

#제출 시각아이디문제언어결과실행 시간메모리
648047gokussjz어르신 집배원 (BOI14_postmen)C++14
55 / 100
620 ms114076 KiB
#include "bits/stdc++.h" #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define all(x) x.begin(), x.end() #define pb push_back #define sz(x) (int)(x.size()) #define ll long long #define fi first #define se second #define lbd lower_bound #define ubd upper_bound template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const int MOD = 1e9 + 7; const double eps = 1e-10; const long long INF = 1e18; const int N = 2e5 + 10; struct Euler_Path { int n; vector<set<int>> adj; vector<int> path; void init(int _n) { n = _n; adj.resize(n); } void add_edge(int u, int v) { adj[u].insert(v); adj[v].insert(u); } void euler_dfs(int u) { while (!adj[u].empty()) { auto v = *adj[u].begin(); adj[u].erase(adj[u].begin()); adj[v].erase(u); euler_dfs(v); } path.pb(u); } } idk; void solve() { int n, m; cin >> n >> m; idk.init(n); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; --u, --v; idk.add_edge(u, v); } idk.euler_dfs(0); vector<int> ans = idk.path; vector<int> cycles; bool vis[n] = {}; vector<vector<int>> fin; for (const auto &it : ans) { if (vis[it]) { vector<int> curr; curr.pb(it); while (cycles.back() != it) { curr.pb(cycles.back()); vis[cycles.back()] = 0; cycles.pop_back(); } fin.pb(curr); } else { vis[it] = 1; cycles.pb(it); } } for (const auto &v : fin) { for (const auto &it : v) cout << it + 1 << ' '; cout << '\n'; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int tt = 1; //cin >> tt; while (tt--) { solve(); cout << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...