66852023-12-16 14:12:29anonAdószedőcpp17Accepted 30/30174ms31748 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, key;
    vector<ll> edge(2);
    queue<array<ll, 3>> q;
    cin >> N >> M >> capital;
    unordered_set<ll> ans(M);
    vector<vector<ll>> G(N + 1);
    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]) {
            edge[0] = cs[0];
            edge[1] = cs[1];
            sort(edge.begin(), edge.end());
            key = edge[0] | (edge[1] << 32);
            if(ans.find(key) != ans.end())
                continue;
            ans.insert(key);
        }
        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 & ((1LL << 32) - 1)) << ' ' << (x >> 32) << '\n';
    return 0;
}

SubtaskSumTestVerdictTimeMemory
base30/30
1Accepted0/03ms1828 KiB
2Accepted0/0136ms24732 KiB
3Accepted1/13ms2352 KiB
4Accepted1/13ms2436 KiB
5Accepted1/13ms2472 KiB
6Accepted1/13ms2552 KiB
7Accepted1/13ms2768 KiB
8Accepted1/13ms3040 KiB
9Accepted2/23ms3208 KiB
10Accepted2/24ms3268 KiB
11Accepted2/24ms3264 KiB
12Accepted2/212ms4788 KiB
13Accepted2/226ms7492 KiB
14Accepted2/2111ms21944 KiB
15Accepted1/1150ms29340 KiB
16Accepted1/1122ms24844 KiB
17Accepted2/2165ms30992 KiB
18Accepted2/2152ms28552 KiB
19Accepted2/2174ms29748 KiB
20Accepted2/2160ms30760 KiB
21Accepted2/2168ms31748 KiB