Submission #991111

#TimeUsernameProblemLanguageResultExecution timeMemory
991111yellowtoadSenior Postmen (BOI14_postmen)C++17
100 / 100
230 ms78984 KiB
#include <iostream> #include <vector> #define f first #define s second using namespace std; int n, m, vis[500010], viss[500010]; vector<pair<int,int>> edge[500010]; vector<vector<int>> path; vector<int> pth; inline bool dfs(int u, int tar, int can) { pth.push_back(u); if ((u == tar) && (can)) { path.push_back(pth); return 1; } while ((edge[u].size()) && (vis[edge[u].back().s])) edge[u].pop_back(); if (edge[u].empty()) return 0; vis[edge[u].back().s] = 1; return dfs(edge[u].back().f,tar,1); } inline void solve(int u) { pth.clear(); if (!dfs(u,u,0)) return; int iter = path.size()-1; vector<int> stk; for (int i = 0; i < path[iter].size(); i++) { if (viss[path[iter][i]]) { cout << path[iter][i]; while (stk.back() != path[iter][i]) { cout << " " << stk.back(); viss[stk.back()] = 0; stk.pop_back(); } cout << "\n"; } else { viss[path[iter][i]] = 1; stk.push_back(path[iter][i]); } } for (int i = 0; i < path[iter].size(); i++) viss[path[iter][i]] = 0; for (int i = 0; i < path[iter].size()-1; i++) solve(path[iter][i]); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; edge[u].push_back({v,i}); edge[v].push_back({u,i}); } solve(1); }

Compilation message (stderr)

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