76842024-01-10 13:06:17UnluckYAdószedőcpp17Accepted 30/30483ms21672 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{

    int n, m, f; cin >> n >> m >> f;
    vector<vector<int>> v(n+1);
    vector<pair<int, int>> elek;
    for (int i = 0; i < m; i++){
        int a, b; cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
        elek.push_back({a, b});
    }

    vector<int> d(n+1, 1e9);
    queue<int> q;
    q.push(f);
    d[f] = 0;

    while (!q.empty()){
        int x = q.front();
        q.pop();
        for (int i : v[x]){
            if (d[i] > d[x] + 1){
                d[i] = d[x]+1;
                q.push(i);
            }
        }

    }

    vector<pair<int, int>> me;

    for (auto i : elek){
        if (d[i.first] + 1 == d[i.second] || d[i.second] + 1 == d[i.first]) me.push_back(i);
    }

    cout << me.size() << endl;

    for (auto i : me) cout << i.first << " " << i.second << endl;



    return 0;
}
SubtaskSumTestVerdictTimeMemory
base30/30
1Accepted0/03ms1816 KiB
2Accepted0/0367ms16268 KiB
3Accepted1/13ms2404 KiB
4Accepted1/13ms2640 KiB
5Accepted1/13ms2824 KiB
6Accepted1/13ms3000 KiB
7Accepted1/13ms3080 KiB
8Accepted1/13ms3204 KiB
9Accepted2/24ms3608 KiB
10Accepted2/27ms3600 KiB
11Accepted2/26ms3600 KiB
12Accepted2/226ms5012 KiB
13Accepted2/259ms6644 KiB
14Accepted2/2331ms15592 KiB
15Accepted1/1448ms21500 KiB
16Accepted1/1354ms17064 KiB
17Accepted2/2446ms21624 KiB
18Accepted2/2483ms20784 KiB
19Accepted2/2456ms21528 KiB
20Accepted2/2358ms21672 KiB
21Accepted2/2379ms21644 KiB