45642023-03-29 21:05:17Valaki2Adószedőcpp14Accepted 30/3096ms20916 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

void solve() {
    int n, m, f;
    cin >> n >> m >> f;
    vector<vector<int> > g(1 + n);
    vector<pii > edges(m);
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        edges[i].fi = a;
        edges[i].se = b;
        g[a].pb(b);
        g[b].pb(a);
    }
    vector<int> dist(1 + n, -1);
    queue<int> q;
    dist[f] = 0;
    q.push(f);
    while(!q.empty()) {
        int cur = q.front();
        q.pop();
        for(int nei : g[cur]) {
            if(dist[nei] == -1) {
                dist[nei] = dist[cur] + 1;
                q.push(nei);
            }
        }
    }
    vector<pii > ans;
    for(const pii &p : edges) {
        if(dist[p.fi] != dist[p.se]) {
            ans.pb(p);
        }
    }
    cout << (int) ans.size() << "\n";
    for(const pii &p : ans) {
        cout << p.fi << " " << p.se << "\n";
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base30/30
1Accepted0/03ms1828 KiB
2Accepted0/076ms14336 KiB
3Accepted1/13ms2112 KiB
4Accepted1/13ms2244 KiB
5Accepted1/13ms2340 KiB
6Accepted1/13ms2548 KiB
7Accepted1/13ms2756 KiB
8Accepted1/13ms2772 KiB
9Accepted2/23ms3188 KiB
10Accepted2/23ms3428 KiB
11Accepted2/24ms3644 KiB
12Accepted2/28ms5000 KiB
13Accepted2/217ms6708 KiB
14Accepted2/264ms14400 KiB
15Accepted1/185ms20128 KiB
16Accepted1/170ms16328 KiB
17Accepted2/294ms20668 KiB
18Accepted2/286ms19824 KiB
19Accepted2/290ms20332 KiB
20Accepted2/290ms20892 KiB
21Accepted2/296ms20916 KiB