제출 #991096

#제출 시각아이디문제언어결과실행 시간메모리
991096yellowtoad어르신 집배원 (BOI14_postmen)C++17
0 / 100
10 ms25944 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); } } } 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()-1; 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); }

컴파일 시 표준 에러 (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:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for (int i = 0; i < path[iter].size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~~~~
postmen.cpp:44:23: 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 < path[iter].size()-1; i++) viss[i] = 0;
      |                     ~~^~~~~~~~~~~~~~~~~~~~~
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()-1; i++) solve(path[iter][i]);
      |                     ~~^~~~~~~~~~~~~~~~~~~~~
postmen.cpp: In function 'bool dfs(int, int, int)':
postmen.cpp:24:1: warning: control reaches end of non-void function [-Wreturn-type]
   24 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...