63712023-11-26 09:39:34horvathabelAdószedőcpp17Accepted 30/30474ms26904 KiB
#include <bits/stdc++.h>
using namespace std;
vector<int> tav;
vector<int> g[60001];
vector<pair<int,int>> good;
void bfs(int s){
    queue<int> q;
    q.push(s);
    while (!q.empty()){
        int v=q.front();
        q.pop();
        for (int edge:g[v]){
            if (tav[edge]==1e9){
                tav[edge]=tav[v]+1;
                q.push(edge);
                good.push_back({v,edge});
            }
            else{
                if (tav[edge]==tav[v]+1) good.push_back({v,edge});
            }
        }
    }
    cout<<good.size()<<endl;
    for (auto x:good) cout<<x.first<<" "<<x.second<<endl;
}
int main()
{

    vector<pair<int,int>> good;
    int n,m,k;
    cin>>n>>m>>k;
    tav.resize(n+1,1e9);
    tav[k]=0;
    for (int i=0; i<m;i++){
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    bfs(k);

}
SubtaskSumTestVerdictTimeMemory
base30/30
1Accepted0/04ms4628 KiB
2Accepted0/0379ms14028 KiB
3Accepted1/14ms6840 KiB
4Accepted1/14ms7072 KiB
5Accepted1/14ms7280 KiB
6Accepted1/14ms7132 KiB
7Accepted1/14ms7356 KiB
8Accepted1/14ms7620 KiB
9Accepted2/24ms7860 KiB
10Accepted2/26ms7832 KiB
11Accepted2/26ms8096 KiB
12Accepted2/226ms8980 KiB
13Accepted2/259ms10364 KiB
14Accepted2/2312ms16576 KiB
15Accepted1/1449ms22828 KiB
16Accepted1/1365ms21376 KiB
17Accepted2/2368ms26508 KiB
18Accepted2/2395ms26060 KiB
19Accepted2/2474ms26424 KiB
20Accepted2/2363ms26824 KiB
21Accepted2/2354ms26904 KiB