Submission #1124865

#TimeUsernameProblemLanguageResultExecution timeMemory
1124865TahirAliyevSenior Postmen (BOI14_postmen)C++20
38 / 100
1096 ms31236 KiB
#include <bits/stdc++.h> // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define int long long #define ld long double #define ll long long #define pii pair<int, int> #define all(v) v.begin(), v.end() using namespace std; const int oo = 1e9 + 9; const int MAX = 5e5 + 6, LOGMAX = 20, B = 400, MOD = 1e9 + 7; int n, m; vector<pii> g[MAX]; int vis[MAX]; vector<int> path; void dfs(int node){ for(pii to : g[node]){ if(vis[to.second]) continue; vis[to.second] = 1; dfs(to.first); } path.push_back(node); } void solve(){ cin >> n >> m; for(int i = 1; i <= m; i++){ int u, v; cin >> u >> v; g[u].push_back({v, i}); g[v].push_back({u, i}); } dfs(1); memset(vis, 0, sizeof(vis)); vector<vector<int>> ans; vector<int> cur; for(int a : path){ if(vis[a]){ vector<int> v; while(cur.size()){ v.push_back(cur.back()); if(cur.back() == a){ cur.pop_back(); break; } cur.pop_back(); } ans.push_back(v); for(int u : v) vis[u] = 0; } cur.push_back(a); vis[a] = 1; } for(auto v : ans){ for(int a : v) cout << a << ' '; cout << '\n'; } } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while(t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...