Submission #1260687

#TimeUsernameProblemLanguageResultExecution timeMemory
1260687chikien2009Senior Postmen (BOI14_postmen)C++20
0 / 100
5 ms12104 KiB
#include <bits/stdc++.h>

using namespace std;

void setup()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int n, m, a, b;
bool check[500000];
vector<pair<int, int>> g[500000];
vector<int> v, q;

inline bool DFS(int node)
{
    while (!g[node].empty() && check[g[node].back().second])
    {
        g[node].pop_back();
    }
    if (!g[node].empty())
    {
        a = g[node].back().first;
        v.push_back(g[node].back().first);
        cout << g[node].back().second + 1 << " ";
        check[g[node].back().second] = true;
        g[node].pop_back();
        DFS(a);
        return true;
    }
    return false;
}

int main()
{
    setup();

    cin >> n >> m;
    for (int i = 0; i < m; ++i)
    {
        cin >> a >> b;
        g[a - 1].push_back({b - 1, i});
        g[b - 1].push_back({a - 1, i});
    }
    for (int i = 0; i < n; ++i)
    {
        while (!g[i].empty())
        {
            if (DFS(i))
            {
                cout << "\n";
            }
        }
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...