Submission #1293709

#TimeUsernameProblemLanguageResultExecution timeMemory
1293709SSKMFSenior Postmen (BOI14_postmen)C++20
0 / 100
1 ms23868 KiB
#include <bits/stdc++.h>
using namespace std;

pair <int , int> muchie[1000000];
int capat[500001] , locatie[500001] , stiva[500001];
bool blocat[500000];

inline void Parcurgere (const int nod)
{
    for (int& indice = capat[nod] ; indice != -1 ; ) {
        if (blocat[indice >> 1])
            { indice = muchie[indice].second; }
        else
        {
            const int vecin = muchie[indice].first;
            blocat[indice >> 1] = true;
            indice = muchie[indice].second;

            Parcurgere(vecin);
        }
    }
    
    if (!locatie[nod])
    {
        stiva[++stiva[0]] = nod;
        locatie[nod] = stiva[0];
    }
    else
    {
        for (int indice = locatie[nod] + 1 ; indice <= stiva[0] ; indice++)
        {
            cout << stiva[indice] << ' ';
            locatie[stiva[indice]] = 0;
        }

        cout << nod << '\n';

        stiva[0] = locatie[nod];
    }
}

int main()
{
    ios :: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
 
    int numar_noduri , numar_muchii;
    cin >> numar_noduri >> numar_muchii;

    for (int indice = 1 ; indice <= numar_noduri ; indice++)
        { capat[indice] = -1; }

    for (int indice = 0 ; indice < numar_muchii ; indice++)
    {
        int nod[2]; cin >> nod[0] >> nod[1];
        muchie[2 * indice] = {nod[0] , capat[nod[1]]}; capat[nod[1]] = 2 * indice;
        muchie[2 * indice + 1] = {nod[1] , capat[nod[0]]}; capat[nod[0]] = 2 * indice + 1;
    }

    Parcurgere(1);

    for (int indice = 1 ; indice <= stiva[0] ; indice++)
        { cout << stiva[indice] << ' '; }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...