제출 #734548

#제출 시각아이디문제언어결과실행 시간메모리
734548DAleksa어르신 집배원 (BOI14_postmen)C++17
100 / 100
454 ms77552 KiB
#include <bits/stdc++.h> using namespace std; struct edge { int v; int id; }; const int N = 5e5 + 10; vector<edge> g[N]; int n, m; vector<int> eulerian_cycle; bool mark[N]; int cnt[N]; int id = 0; stack<int> stk; int idx[N]; void find_eulerian_cycle(int u) { for(; idx[u] < (int)g[u].size(); idx[u]++) { edge v = g[u][idx[u]]; if(mark[v.id]) continue; mark[v.id] = true; find_eulerian_cycle(v.v); eulerian_cycle.push_back(v.v); } } int main() { scanf("%d%d", &n, &m); for(int i = 0; i < m; i++) { int u, v; scanf("%d%d", &u, &v); // int I = i / 3; // if(i % 3 == 0) { // u = 1; // v = 2 * I + 2; // } else if(i % 3 == 1) { // u = 1; // v = 2 * I + 3; // } else { // u = 2 * I + 2; // v = 2 * I + 3; // } g[u].push_back({v, id}); g[v].push_back({u, id++}); } find_eulerian_cycle(1); eulerian_cycle.push_back(1); //for(int i = 0; i < eulerian_cycle.size(); i++) printf("%d ", eulerian_cycle[i]); //printf("\n\n"); stk.push(eulerian_cycle[0]); cnt[eulerian_cycle[0]]++; for(int i = 1; i < eulerian_cycle.size(); i++) { if(cnt[eulerian_cycle[i]] > 0) { printf("%d ", eulerian_cycle[i]); while(stk.top() != eulerian_cycle[i]) { printf("%d ", stk.top()); cnt[stk.top()]--; stk.pop(); } printf("\n"); } else { cnt[eulerian_cycle[i]]++; stk.push(eulerian_cycle[i]); } } return 0; }

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

postmen.cpp: In function 'int main()':
postmen.cpp:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for(int i = 1; i < eulerian_cycle.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~~
postmen.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     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", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...