# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
42315 | IvanC | Senior Postmen (BOI14_postmen) | C++14 | 656 ms | 108048 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,posicao[MAXN],marcado[MAXN];
set<int> cjt[MAXN];
vi pilha,temporario;
vector<vi> resposta;
void dfs(int v){
marcado[v] = 1;
posicao[v] = pilha.size();
pilha.push_back(v);
while(!cjt[v].empty() && posicao[v] != -1){
int u = *(cjt[v].begin());
cjt[v].erase(u);
cjt[u].erase(v);
if(marcado[u]){
for(int i = posicao[v];i>posicao[u];i--){
int k = pilha[i];
posicao[k] = -1;
marcado[k] = 0;
temporario.push_back(k);
pilha.pop_back();
}
temporario.push_back(u);
resposta.push_back(temporario);
temporario.clear();
return;
}
else{
dfs(u);
}
}
if(posicao[v] == -1) return;
}
int main(){
scanf("%d %d",&N,&M);
for(int i = 1;i<=N;i++) posicao[i] = -1;
for(int i = 1;i<=M;i++){
int u,v;
scanf("%d %d",&u,&v);
cjt[u].insert(v);
cjt[v].insert(u);
}
for(int i = 1;i<=N;i++){
if(!cjt[i].empty()) 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... |