제출 #1309456

#제출 시각아이디문제언어결과실행 시간메모리
1309456Balsa어르신 집배원 (BOI14_postmen)C++20
0 / 100
3 ms23868 KiB
#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

using ll = long long;
const ll MAXN = 500005, MAXM = 500005;

vector<pair<ll, ll>> edges[MAXN];
bool seen[MAXM], vis[MAXN];
vector<ll> path;

void dfs(ll v) {
    vis[v] = 1;

    for (auto[u, id] : edges[v]) {
        if (seen[id] || vis[u]) continue;
        seen[id] = 1;
        dfs(u);
    }

    path.push_back(v);
}

void solve() {
    ll n, m;
    cin >> n >> m;
    for (ll i = 0; i < m; i++) {
        ll v, u;
        cin >> v >> u;
        v--, u--;
        edges[v].push_back({u, i});
        edges[u].push_back({v, i});
    }

    for (ll v = 0; v < n; v++) {
        memset(vis, 0, sizeof(vis));
        path.clear();
        dfs(v);

        path.pop_back();
        if (path.empty()) continue;
        for (ll x : path) cout << x+1 << ' ';
        cout << '\n';
    }
}

int main() {
    // freopen("promote.in", "r", stdin);
    // freopen("promote.out", "w", stdout);
 
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...