Submission #1119671

#TimeUsernameProblemLanguageResultExecution timeMemory
1119671sasdeSenior Postmen (BOI14_postmen)C++17
100 / 100
496 ms69496 KiB
#include<bits/stdc++.h> #define str string #define task "strdel" #define ii pair<int,int> #define iii pair<int,ii> #define iv pair<ii,ii> #define se second #define fi first #define ffi fi.fi #define sfi se.fi #define sse se.se #define fse fi.se #define lt(i, c, d) for(int i = c; i <= d; ++i) #define fl(i, c, d) for(int i = d; i >= c; --i) #define pb push_back #define emb emplace_back #define em emplace using namespace std; const int N=1e6+5,lg=20,mod=998244353; mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); int Rand(int u,int v){ return u+rd()%(v-u+1); } int n,m; vector<ii>a[N]; bool k[N],k1[N]; list<int> eul(int u){ list<int> ans={u}; while(!a[u].empty()){ k1[u]=true; int v=a[u].back().fi; int i=a[u].back().se; a[u].pop_back(); if(k[i])continue; k[i]=true; u=v; ans.emb(u); } for(auto it=++ans.begin();it!=ans.end();++it){ auto t=eul(*it); t.pop_back(); // cout <<*it<<" "<<t.size()<<'\n'; ans.splice(it,t); // ans.insert(it,t.begin(), t.end()); } return ans; } bool h[N]; void solve(){ cin >> n >> m; for(int i=1;i<=m;++i){ int u,v; cin >> u >> v; a[u].emb(v,i); a[v].emb(u,i); } // for(int i:res)cout<<i<<" ";cout<<'\n'; for(int i=1;i<=n;++i) if(!k1[i]){ list<int>res=eul(i); stack<int>s; for(int i:res){ if(h[i]){ while(!s.empty()&&h[i]){ h[s.top()]=false; cout <<s.top()<<" "; s.pop(); } cout<<'\n'; } h[i]=true; s.push(i); } } // cout <<1; } main() { srand(time(0)); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); if(fopen(task".inp","r")){ freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } int t=1; // cin >> t; while(t--){ solve(); // cout<<'\n'; } }

Compilation message (stderr)

postmen.cpp:82:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   82 | main()
      | ^~~~
postmen.cpp: In function 'int main()':
postmen.cpp:89:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |       freopen(task".inp","r",stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
postmen.cpp:90:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |       freopen(task".out","w",stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...