66432023-12-14 18:17:35mmatedAdószedőcpp17Runtime error 25/30174ms27220 KiB
#include <bits/stdc++.h>
using namespace std;
#define f(i,k,n) for(int i=k; i<n; i++)
#define ll long long
const int inf = INT_MAX;
vector<vector<int>>g(60001);
void solve()
{
    int n,k,f;
    cin>>n>>k>>f;
    set<pair<int,int>>c;
    int a,b;
    f(i,0,k)
    {
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    queue<int> q;
    q.push(f);
    vector<int> d(n,inf);
    vector<bool> v(n,false);
    d[f]=0;
    v[f]=true;
    while(!q.empty())
    {
        int w=q.front();
        q.pop();
        for(auto u : g[w])
        {
            if(v[u]==false)
            {
                v[u]=true;
                d[u]=d[w]+1;
                a=min(u,w);
                b=max(u,w);
                c.insert(make_pair(a,b));
                q.push(u);
            }
            else if(d[u]-d[w]==1)
            {
                a=min(u,w);
                b=max(u,w);
                c.insert(make_pair(a,b));
            }

        }
    }
    cout<<c.size()<<"\n";
    for(pair<int,int> p : c)    cout<<p.first<<" "<<p.second<<"\n";
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    //cin>>t;
    while(t--)  solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base25/30
1Accepted0/04ms4564 KiB
2Accepted0/0143ms22056 KiB
3Accepted1/14ms4948 KiB
4Accepted1/14ms5284 KiB
5Accepted1/14ms5384 KiB
6Accepted1/14ms5456 KiB
7Runtime error0/14ms5688 KiB
8Accepted1/14ms5552 KiB
9Accepted2/24ms5688 KiB
10Accepted2/24ms5684 KiB
11Accepted2/24ms6020 KiB
12Accepted2/213ms7328 KiB
13Accepted2/228ms9776 KiB
14Wrong answer0/2115ms20340 KiB
15Accepted1/1163ms25348 KiB
16Accepted1/1128ms22396 KiB
17Accepted2/2174ms27076 KiB
18Accepted2/2168ms25344 KiB
19Wrong answer0/2168ms26096 KiB
20Accepted2/2159ms26532 KiB
21Accepted2/2171ms27220 KiB