66812023-12-16 13:51:05anonAdószedőcpp17Runtime error 12/3056ms64844 KiB
#include <bits/stdc++.h>
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef long long ll;
using namespace std;
const ll INF = ~(1LL << 63);
int main() {
    FastIO;
    ll i, N, M, capital, n1, n2;
    queue<array<ll, 3>> q;
    vector<array<ll, 2>> ans;
    cin >> N >> M >> capital;
    vector<vector<ll>> G(N + 1);
    vector<vector<bool>> G2(N + 1, vector<bool>(N + 1, false));
    vector<ll> dist(N + 1, INF);
    for(i = 0; i < M; i++) {
        cin >> n1 >> n2;
        G[n1].push_back(n2);
        G[n2].push_back(n1);
    }
    q.push({ capital, 0, 0 });
    while(!q.empty()) {
        array<ll, 3> cs = q.front();
        q.pop();
        if(dist[cs[0]] < cs[2])
            continue;
        dist[cs[0]] = cs[2];
        if(cs[1] && !G2[cs[1]][cs[0]]) {
            G2[cs[1]][cs[0]] = G2[cs[0]][cs[1]] = true;
            ans.push_back({ cs[1], cs[0] });
        }
        for(const auto &x : G[cs[0]]) {
            if(dist[x] > cs[2])
                q.push({ x, cs[0], cs[2] + 1 });
        }
    }
    cout << ans.size() << '\n';
    for(const auto &x : ans)
        cout << x[0] << ' ' << x[1] << '\n';
    return 0;
}

SubtaskSumTestVerdictTimeMemory
base12/30
1Accepted0/03ms1824 KiB
2Runtime error0/032ms64844 KiB
3Accepted1/13ms2436 KiB
4Accepted1/13ms2404 KiB
5Accepted1/13ms2836 KiB
6Accepted1/13ms2808 KiB
7Accepted1/13ms2752 KiB
8Accepted1/132ms28244 KiB
9Accepted2/23ms3384 KiB
10Accepted2/24ms3592 KiB
11Accepted2/24ms3596 KiB
12Runtime error0/256ms64004 KiB
13Runtime error0/252ms63768 KiB
14Runtime error0/232ms63760 KiB
15Runtime error0/128ms63744 KiB
16Runtime error0/128ms63740 KiB
17Runtime error0/227ms63504 KiB
18Runtime error0/228ms63472 KiB
19Runtime error0/228ms63292 KiB
20Runtime error0/227ms63284 KiB
21Runtime error0/227ms63212 KiB