Submission #1119684

#TimeUsernameProblemLanguageResultExecution timeMemory
1119684vjudge1Senior Postmen (BOI14_postmen)C++17
55 / 100
510 ms59604 KiB
#include <bits/stdc++.h> #define fi first #define se second using namespace std; const int maxn = 5e5 + 5; int n, m; vector<vector<pair<int, int>>> g; vector<int> path; vector<bool> seen; bool vs[maxn]; void dfs(int node) { while (!g[node].empty()) { int son = g[node].back().fi, idx = g[node].back().se; // auto [son, idx] = g[node].back(); g[node].pop_back(); if (seen[idx]) { continue; } seen[idx] = true; dfs(son); } path.push_back(node); } int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); // freopen("main.inp", "r", stdin); cin >> n >> m; g.resize(n+1); seen.resize(m+1); for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; g[x].push_back({y, i}); g[y].push_back({x, i}); } dfs(1); // for (int x : path) cout << x << " "; // cout << endl; stack<int> st; for (int i = 0; i < path.size(); i++) { if (vs[path[i]]) { while(!st.empty() && st.top() != path[i]) { cout << st.top() << " "; vs[st.top()] = 0; st.pop(); } cout << st.top() << " "; st.pop(); cout << endl; } st.push(path[i]); vs[path[i]] = 1; } }

Compilation message (stderr)

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