# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
42314 | IvanC | Senior Postmen (BOI14_postmen) | C++14 | 667 ms | 76280 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>
using namespace std;
typedef vector<int> vi;
const int MAXN = 5*1e5 + 10;
int N,M,e1[MAXN],e2[MAXN],e3[MAXN],marcado[MAXN],ptr[MAXN];
vi grafo[MAXN],pilha;
vector<vi> resposta;
int dfs(int v){
//printf("DFS %d\n",v);
marcado[v] = 1;
for(;ptr[v] < grafo[v].size();ptr[v]++){
int idx = grafo[v][ptr[v]];
if(e3[idx] == 1) continue;
e3[idx] = 1;
int u = (e1[idx] != v) ? (e1[idx]) : (e2[idx]);
if(marcado[u]){
marcado[v] = 0;
pilha.push_back(v);
return u;
}
int ret = dfs(u);
if(ret == v){
pilha.push_back(v);
resposta.push_back(pilha);
pilha.clear();
}
else{
marcado[v] = 0;
pilha.push_back(v);
return ret;
}
}
marcado[v] = 0;
pilha.clear();
return -1;
}
int main(){
scanf("%d %d",&N,&M);
for(int i = 1;i<=M;i++){
scanf("%d %d",&e1[i],&e2[i]);
grafo[e1[i]].push_back(i);
grafo[e2[i]].push_back(i);
}
for(int i = 1;i<=N;i++){
dfs(i);
}
for(int i = 0;i<resposta.size();i++){
for(int j : resposta[i]) printf("%d ",j);
printf("\n");
}
return 0;
}
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... |