Submission #997030

#TimeUsernameProblemLanguageResultExecution timeMemory
997030mkolaSenior Postmen (BOI14_postmen)C++14
0 / 100
13 ms25888 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define sz size #define all(x) begin(x), end(x) #define ll long long #define INF 1e18 #define MOD (int)(1e9 + 7) int N, M, cnt[500005]; vector<pair<int, int>> adj[500005]; vector<int> cycle; vector<vector<int>> cycles; bool seen[500005]; void dfs(int v) { while(adj[v].sz()) { pair<int, int> p = adj[v].back(); adj[v].pop_back(); int u = p.first, id = p.second; if(!seen[id]) { seen[id] = true; dfs(u); } } cycle.pb(v); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> N >> M; for(int i = 0; i < M; ++i) { int a, b; cin >> a >> b; adj[a].pb({b, i}); adj[b].pb({a, i}); } dfs(1); stack<int> st; for(int i = 0; i < cycle.sz(); ++i) { int u = cycle[i]; cnt[u]++; st.push(u); if(cnt[u] > 1) { vector<int> v; v.pb(u), st.pop(); while(st.top() != u) { int p = st.top(); v.pb(p); cnt[p]--; st.pop(); } cycles.pb(v); } } for(auto const &cyc : cycles) { for(int v : cyc) cout << v << ' '; cout << '\n'; } return 0; }

Compilation message (stderr)

postmen.cpp: In function 'int main()':
postmen.cpp:44:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  for(int i = 0; i < cycle.sz(); ++i) {
      |                 ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...