73812024-01-08 12:36:20EsVagyAdószedőcpp17Elfogadva 30/30105ms17204 KiB
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <climits>
#include <queue>
#include <fstream>
#include <sstream>
#include <math.h>
#include <list>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m, s;
    cin >> n >> m >> s;
    s--;
    vector<vector<int>> g(n, vector<int>());
    vector<bool> visited(n, false);
    vector<int> dist(n, INT_MAX);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<pair<int, int>> roads;
    queue<int> q;
    q.push(s);
    visited[s] = true;
    dist[s] = 0;
    while (!q.empty())
    {
        int next = q.front();
        q.pop();
        for (int node : g[next])
        {
            if (!visited[node])
            {
                q.push(node);
                roads.push_back(pair<int, int>(next, node));
                visited[node] = true;
                dist[node] = dist[next] + 1;
            }
            else
            {
                if (dist[node] == dist[next] + 1)
                {
                    roads.push_back(pair<int, int>(next, node));
                }
            }
        }
    }

    cout << roads.size() << "\n";
    for (pair<int, int> p : roads)
    {
        cout << p.first + 1 << " " << p.second + 1 << "\n";
    }
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base30/30
1Elfogadva0/03ms1828 KiB
2Elfogadva0/086ms11668 KiB
3Elfogadva1/13ms2244 KiB
4Elfogadva1/13ms2456 KiB
5Elfogadva1/13ms2672 KiB
6Elfogadva1/13ms2884 KiB
7Elfogadva1/13ms2976 KiB
8Elfogadva1/13ms3072 KiB
9Elfogadva2/23ms3400 KiB
10Elfogadva2/24ms3504 KiB
11Elfogadva2/24ms3632 KiB
12Elfogadva2/28ms4624 KiB
13Elfogadva2/218ms5948 KiB
14Elfogadva2/275ms11552 KiB
15Elfogadva1/197ms16888 KiB
16Elfogadva1/179ms13168 KiB
17Elfogadva2/2105ms17120 KiB
18Elfogadva2/297ms16184 KiB
19Elfogadva2/2103ms16824 KiB
20Elfogadva2/2101ms17180 KiB
21Elfogadva2/2101ms17204 KiB