Submission #881107

#TimeUsernameProblemLanguageResultExecution timeMemory
881107RequiemSenior Postmen (BOI14_postmen)C++17
100 / 100
428 ms82360 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,v,m,deg[MAXN],complexity=0; bool used[MAXN]; bool solve[MAXN]; ii edge[MAXN]; vector<int> ans; void dfs(int u){ while(!g[u].empty()){ int id = g[u].back(); g[u].pop_back(); if (used[id]) continue; used[id] = true; int v = edge[id].fi + edge[id].se - u; dfs(v); } ans.pb(u); } 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); deg[edge[i].fi]++; deg[edge[i].se]++; } memset(inqueue,false,sizeof(inqueue)); // for(auto x: ans){ // cout<<x<<' '; // } // cout<<endl; for(int i=1;i<=n;i++){ if (deg[i]&1) { cout<<"IMPOSSIBLE"<<endl; return 0; } } memset(used,false,sizeof(used)); dfs(1); if (ans.size() != m + 1) { cout<<"IMPOSSIBLE"<<endl; return 0; } stack<int> st; 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; }

Compilation message (stderr)

postmen.cpp:40:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   40 | main()
      | ^~~~
postmen.cpp: In function 'int main()':
postmen.cpp:49:13: warning: unused variable 'u' [-Wunused-variable]
   49 |         int u,v;
      |             ^
postmen.cpp:49:15: warning: unused variable 'v' [-Wunused-variable]
   49 |         int u,v;
      |               ^
postmen.cpp:71:20: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   71 |     if (ans.size() != m + 1) {
      |         ~~~~~~~~~~~^~~~~~~~
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(TASKNAME".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(TASKNAME".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...