Submission #991082

#TimeUsernameProblemLanguageResultExecution timeMemory
991082yellowtoadSenior Postmen (BOI14_postmen)C++17
0 / 100
1098 ms13148 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; bool dfs(int u, int tar, int can) { pth.push_back(u); if (can) viss[u] = 1; if ((u == tar) && (can)) { path.push_back(pth); return 1; } for (int i = 0; i < edge[u].size(); i++) { if ((!vis[edge[u][i].s]) && (!viss[edge[u][i].f])) { vis[edge[u][i].s] = 1; if (dfs(edge[u][i].f,tar,1)) return 1; vis[edge[u][i].s] = 0; } } if (can) viss[u] = 0; pth.pop_back(); return 0; } void solve(int u) { if (!dfs(u,u,0)) return; int iter = path.size()-1; for (int i = 0; i < path[iter].size(); i++) viss[path[iter][i]] = 0; pth.clear(); if (path[iter].size() == 1) return; for (int i = 0; i < path[iter].size()-1; i++) cout << path[iter][i] << " "; cout << endl; for (int i = 0; i < path[iter].size()-1; i++) solve(path[iter][i]); } int main() { 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 'bool dfs(int, int, int)':
postmen.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int i = 0; i < edge[u].size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~
postmen.cpp: In function 'void solve(int)':
postmen.cpp:34:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for (int i = 0; i < path[iter].size(); i++) viss[path[iter][i]] = 0;
      |                     ~~^~~~~~~~~~~~~~~~~~~
postmen.cpp:37:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for (int i = 0; i < path[iter].size()-1; i++) cout << path[iter][i] << " ";
      |                     ~~^~~~~~~~~~~~~~~~~~~~~
postmen.cpp:39:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     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...