제출 #987700

#제출 시각아이디문제언어결과실행 시간메모리
987700anonymous321어르신 집배원 (BOI14_postmen)C++17
55 / 100
631 ms93800 KiB
// https://oj.uz/problem/view/BOI14_postmen #include <bits/stdc++.h> using namespace std; vector<vector<int>> adj_list; vector<vector<int>> other_id; vector<int> active; vector<int> tour {}; void hhz (int v) { while (adj_list[v].size() > active[v]) { int it = adj_list[v][active[v]]; int it_id = other_id[v][active[v]]; other_id[adj_list[it][active[it]]][other_id[it][active[it]]] = it_id; swap(adj_list[it][it_id], adj_list[it][active[it]]); swap(other_id[it][it_id], other_id[it][active[it]]); active[it]++; active[v]++; hhz(it); } tour.push_back(v); } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; scanf("%d %d", &n, &m); adj_list = vector<vector<int>>(n); other_id = vector<vector<int>>(n); active = vector<int>(n, 0); for (int i = 0; i < m; i++) { int a, b; scanf("%d %d", &a, &b); other_id[a-1].push_back(adj_list[b-1].size()); other_id[b-1].push_back(adj_list[a-1].size()); adj_list[a-1].push_back(b-1); adj_list[b-1].push_back(a-1); } hhz(0); stack<int> s {}; vector<bool> in_s (n, false); vector<vector<int>> sol {}; for (int i = 0; i < tour.size(); i++) { if (in_s[tour[i]]) { vector<int> subtour {tour[i]}; while (!s.empty() && s.top() != tour[i]) { subtour.push_back(s.top()); in_s[s.top()] = false; s.pop(); } sol.push_back(subtour); } else { in_s[tour[i]] = true; s.push(tour[i]); } } for (auto& it: sol) { for (int& v: it) { printf("%d ", v+1); } printf("\n"); } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

postmen.cpp: In function 'void hhz(int)':
postmen.cpp:11:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
   11 |     while (adj_list[v].size() > active[v]) {
postmen.cpp: In function 'int main()':
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 < tour.size(); i++) {
      |                     ~~^~~~~~~~~~~~~
postmen.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
postmen.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...