제출 #881082

#제출 시각아이디문제언어결과실행 시간메모리
881082RequiemSenior Postmen (BOI14_postmen)C++17
0 / 100
6 ms17084 KiB
#include<bits/stdc++.h> #define int long long #define pb push_back #define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); #define MOD 1000000007 #define INF 1e18 #define fi first #define se second #define FOR(i,a,b) for(int i=a;i<=b;i++) #define FORD(i,a,b) for(int i=a;i>=b;i--) #define sz(a) ((int)(a).size()) #define endl '\n' #define pi 3.14159265359 #define TASKNAME "postmen" template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; } template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; } using namespace std; typedef pair<int,int> ii; typedef pair<int,ii> iii; typedef vector<int> vi; const int MAXN = 5e5 + 9; vector<int> g[MAXN]; int n,m; bool used[MAXN]; ii edge[MAXN]; list<int> euler_circuit(int u){ list<int> ans; int v; ans.pb(u); while(!g[u].empty()){ int id = g[u].back(); g[u].pop_back(); if (used[id]) continue; v = edge[id].fi + edge[id].se - u; used[id] = true; u = v; ans.pb(u); } auto it = ans.begin(); it++; for(; it != ans.end(); it++){ list<int> vert = euler_circuit(*it); vert.pop_front(); ans.splice(it,vert); } return ans; } bool inqueue[MAXN]; main() { fast; if (fopen(TASKNAME".inp","r")){ freopen(TASKNAME".inp","r",stdin); freopen(TASKNAME".out","w",stdout); } cin>>n>>m; for(int i=1;i<=m;i++){ int u,v; cin>>edge[i].fi>>edge[i].se; g[edge[i].fi].pb(i); g[edge[i].se].pb(i); } memset(used,false,sizeof(used)); list<int> ans = euler_circuit(1); stack<int> st; memset(inqueue,false,sizeof(inqueue)); // for(auto x: ans){ // cout<<x<<' '; // } // cout<<endl; for(auto x: ans){ if (!inqueue[x]){ inqueue[x] = true; st.push(x); } else{ cout<<x<<' '; while(!st.empty() and st.top() != x){ cout<<st.top()<<' '; inqueue[st.top()] = false; st.pop(); } cout<<endl; } } cout<<endl; }

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

postmen.cpp:49:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   49 | main()
      | ^~~~
postmen.cpp: In function 'int main()':
postmen.cpp:58:13: warning: unused variable 'u' [-Wunused-variable]
   58 |         int u,v;
      |             ^
postmen.cpp:58:15: warning: unused variable 'v' [-Wunused-variable]
   58 |         int u,v;
      |               ^
postmen.cpp:53:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         freopen(TASKNAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
postmen.cpp:54:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         freopen(TASKNAME".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...