# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
881107 | Requiem | Senior Postmen (BOI14_postmen) | C++17 | 428 ms | 82360 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |