# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
31559 | 2017-08-29T09:39:31 Z | Dat160601 | Senior Postmen (BOI14_postmen) | C++14 | 367 ms | 25440 KB |
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define fi first #define se second int n,u,v,m,vis[500007],hav[500007],cnt=0,ed[1000007],to[1000007],last[1000007],pre[1000007]; stack <int> res; vector <int> ans; void addedge(int u,int v,int i){ cnt++; to[cnt]=v; ed[cnt]=i; pre[cnt]=last[u]; last[u]=cnt; cnt++; to[cnt]=u; ed[cnt]=i; pre[cnt]=last[v]; last[v]=cnt; } void dfs(int k){ stack <int> st; st.push(k); while(!st.empty()){ int u=st.top(),ok=0; for(int i=last[u];i;i=pre[i]){ int v=to[i]; int id=ed[i]; last[u]=pre[i]; if(vis[id]==1) continue; vis[id]=1; ok=1; st.push(v); break; } if(!ok){ ans.pb(u); st.pop(); } } } int main(){ scanf("%d %d",&n,&m); for(int i=1;i<=m;i++){ scanf("%d %d",&u,&v); addedge(u,v,i); } dfs(1); stack <int> stl; for(int i=0;i<(int)ans.size();i++){ u=ans[i]; if(hav[u]){ while(!stl.empty() && stl.top()!=u){ printf("%d ",stl.top()); hav[stl.top()]=0; stl.pop(); } printf("%d\n",u); } else{ hav[u]=1; stl.push(u); } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 6 ms | 512 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 6 ms | 512 KB | Output is correct |
7 | Correct | 10 ms | 1024 KB | Output is correct |
8 | Correct | 6 ms | 512 KB | Output is correct |
9 | Correct | 42 ms | 4212 KB | Output is correct |
10 | Correct | 8 ms | 512 KB | Output is correct |
11 | Correct | 8 ms | 512 KB | Output is correct |
12 | Correct | 47 ms | 4292 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 6 ms | 384 KB | Output is correct |
4 | Correct | 6 ms | 512 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 8 ms | 512 KB | Output is correct |
7 | Correct | 12 ms | 1024 KB | Output is correct |
8 | Correct | 5 ms | 512 KB | Output is correct |
9 | Correct | 44 ms | 4232 KB | Output is correct |
10 | Correct | 7 ms | 512 KB | Output is correct |
11 | Correct | 6 ms | 512 KB | Output is correct |
12 | Correct | 51 ms | 4340 KB | Output is correct |
13 | Correct | 51 ms | 5256 KB | Output is correct |
14 | Correct | 66 ms | 4848 KB | Output is correct |
15 | Correct | 47 ms | 4896 KB | Output is correct |
16 | Correct | 52 ms | 5280 KB | Output is correct |
17 | Correct | 56 ms | 4820 KB | Output is correct |
18 | Correct | 49 ms | 5024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 7 ms | 512 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 6 ms | 640 KB | Output is correct |
7 | Correct | 10 ms | 1024 KB | Output is correct |
8 | Correct | 5 ms | 512 KB | Output is correct |
9 | Correct | 42 ms | 4212 KB | Output is correct |
10 | Correct | 6 ms | 512 KB | Output is correct |
11 | Correct | 6 ms | 512 KB | Output is correct |
12 | Correct | 57 ms | 4292 KB | Output is correct |
13 | Correct | 69 ms | 5280 KB | Output is correct |
14 | Correct | 52 ms | 4976 KB | Output is correct |
15 | Correct | 48 ms | 4896 KB | Output is correct |
16 | Correct | 55 ms | 5280 KB | Output is correct |
17 | Correct | 54 ms | 4716 KB | Output is correct |
18 | Correct | 52 ms | 5064 KB | Output is correct |
19 | Correct | 347 ms | 25420 KB | Output is correct |
20 | Correct | 342 ms | 23288 KB | Output is correct |
21 | Correct | 333 ms | 21272 KB | Output is correct |
22 | Correct | 356 ms | 25440 KB | Output is correct |
23 | Correct | 197 ms | 18088 KB | Output is correct |
24 | Correct | 367 ms | 22184 KB | Output is correct |
25 | Correct | 346 ms | 23716 KB | Output is correct |