제출 #1158913

#제출 시각아이디문제언어결과실행 시간메모리
1158913paulxaxa어르신 집배원 (BOI14_postmen)C++20
100 / 100
283 ms61172 KiB
#include <bits/stdc++.h>

#define NMAX 500000
#define LOG 19

#define ll long long int
#define BASE 128
#define MOD 998244353


using namespace std;

ifstream fin("cod.in");
ofstream fout("cod.out");

int vis[NMAX+1];
vector<pair<int,int>> adj[NMAX+1];
bool used[NMAX+1];

vector<int> euler;
void dfs(int x)
{
    while(!adj[x].empty())
    {
        int id = adj[x].back().second;
        int y = adj[x].back().first;
        adj[x].pop_back();
        if(!used[id])
        {
            used[id]=1;
            dfs(y);
        }
    }
    euler.push_back(x);
}

int last[NMAX+1];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    int n,m;
    cin >> n >> m;
    for(int i=1;i<=m;i++)
    {
        int x,y;
        cin >> x >> y;
        adj[x].push_back({y,i});
        adj[y].push_back({x,i});
    }
    dfs(1);
    vector<int> st;
    for(int i : euler)
    {
        if(last[i])
        {
            cout << i << " ";
            while(st.back()!=i)
            {
                last[st.back()]--;
                cout << st.back() << ' ';
                st.pop_back();
            }
            st.pop_back();
            last[i]--;
            cout << '\n';
        }
        st.push_back(i);
        last[i]++;
    }

}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...