Submission #991097

#TimeUsernameProblemLanguageResultExecution timeMemory
991097yellowtoadSenior Postmen (BOI14_postmen)C++17
0 / 100
20 ms27224 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 ((u == tar) && (can)) { path.push_back(pth); return 1; } for (int i = 0; i < edge[u].size(); i++) { if (!vis[edge[u][i].s]) { vis[edge[u][i].s] = 1; return dfs(edge[u][i].f,tar,1); } } return 0; } 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 << endl; } else { viss[path[iter][i]] = 1; stk.push_back(path[iter][i]); } } for (int i = 0; i < path[iter].size(); i++) viss[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 'bool dfs(int, int, int)':
postmen.cpp:18: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]
   18 |     for (int i = 0; i < edge[u].size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~
postmen.cpp: In function 'void solve(int)':
postmen.cpp:32:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int i = 0; i < path[iter].size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~~~~
postmen.cpp:45:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i = 0; i < path[iter].size(); i++) viss[i] = 0;
      |                     ~~^~~~~~~~~~~~~~~~~~~
postmen.cpp:46:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     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...