제출 #1119674

#제출 시각아이디문제언어결과실행 시간메모리
1119674vjudge1어르신 집배원 (BOI14_postmen)C++17
100 / 100
446 ms59244 KiB
#include<bits/stdc++.h> #define ii pair<int,int> #define fi first #define se second //#define int long long #define task "" using namespace std; const int N = 5e5 + 10, mod = 1e9 + 7; const int oo = 1e18; int n, m; struct edge{ int v, id; }; vector<edge> g[N]; bool used_edge[N], vst[N]; stack<int> st; list<int> euler_walk(int u){ list<int> ans; ans.push_back(u); while(!g[u].empty()){ int v = g[u].back().v; int id = g[u].back().id; g[u].pop_back(); if(used_edge[id]) continue; used_edge[id] = 1; u = v; ans.push_back(u); } for(auto it = ++ans.begin(); it != ans.end(); it++){ auto t = euler_walk(*it); t.pop_back(); ans.splice(it, t); } return ans; } main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(task ".inp", "r")){ freopen(task ".inp", "r", stdin); freopen(task ".out", "w", stdout); } cin >> n >> m; for(int i = 1; i <= m; i++){ int u, v; cin >> u >> v; g[u].push_back({v, i}); g[v].push_back({u, i}); } list<int> ans = euler_walk(1); vector<int> v; for(int x : ans) v.push_back(x); for(int i = 0; i < v.size(); i++){ // cout << v[i] << ' '; if(vst[v[i]]){ int x = st.top(); cout << v[i] << ' '; while(x != v[i]){ cout << x << ' '; vst[x] = 0; st.pop(); x = st.top(); } st.pop(); cout << '\n'; } st.push(v[i]); vst[v[i]] = 1; } }

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

postmen.cpp:10:16: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   10 | const int oo = 1e18;
      |                ^~~~
postmen.cpp:41:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   41 | main(){
      | ^~~~
postmen.cpp: In function 'int main()':
postmen.cpp:57:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for(int i = 0; i < v.size(); i++){
      |                    ~~^~~~~~~~~~
postmen.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
postmen.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen(task ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...