제출 #991110

#제출 시각아이디문제언어결과실행 시간메모리
991110yellowtoad어르신 집배원 (BOI14_postmen)C++17
38 / 100
617 ms24448 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 << "\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); }

컴파일 시 표준 에러 (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[path[iter][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...