51392023-04-20 02:48:13SleepyOverlordAdószedőcpp17Accepted 30/30203ms17508 KiB
#include <vector>
#include <string> 
#include <set> 
#include <map> 
#include <unordered_set>
#include <unordered_map>
#include <queue> 
#include <bitset> 
#include <stack>
#include <list>

#include <numeric> 
#include <algorithm> 
#include <random>
#include <chrono>

#include <cstdio>
#include <fstream>
#include <iostream> 
#include <sstream> 
#include <iomanip>
#include <climits>

#include <cctype>
#include <cmath> 
#include <ctime>
#include <cassert>

using namespace std;

#define ULL unsigned long long
#define LL long long
#define PII pair <int, int>
#define VB vector <bool>
#define VI vector <int>
#define VLL vector <LL>
#define VD vector <double>
#define VS vector <string>
#define VPII vector <pair <int, int> >
#define VVI vector < VI >
#define VVB vector < VB >
#define SI set < int >
#define USI unordered_set <int>
#define MII map <int, int>
#define UMII unordered_map <int, int>
#define MS multiset
#define US unordered_set
#define UM unordered_map
#define UMS unordered_multiset
#define UMM unordered_multimap

#define FORN(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

#define SZ size()
#define BG begin() 
#define EN end() 
#define CL clear()
#define X first
#define Y second
#define RS resize
#define PB push_back
#define MP make_pair
#define ALL(x) x.begin(), x.end()
#define INS insert
#define ER erase
#define CNT count

int n, m, source;
VVI g;
VI dist;

void bf()
{
	dist.RS(n + 1, -1);
	queue<int> fifo;
	fifo.push(source);
	dist[source] = 0;
	while (!fifo.empty())
	{
		int node = fifo.front();
		fifo.pop();
		for (int next : g[node])
			if (dist[next] == -1) 
			{
				dist[next] = dist[node] + 1;
				fifo.push(next);
			}
	}
}

int main()
{
	cin >> n >> m >> source;
	g.RS(n + 1);
	FOR(i, 1, m)
	{
		int x, y;
		cin >> x >> y;
		g[x].PB(y);
		g[y].PB(x);
	}

	bf();
	VPII sol;
	FOR(i, 1, n)
		for (int j : g[i])
			if (dist[j] == dist[i] + 1) sol.PB({i, j});

	cout << sol.SZ << "\n";
	for (auto [x, y] : sol) cout << x << " " << y << "\n";

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base30/30
1Accepted0/03ms1812 KiB
2Accepted0/0165ms11788 KiB
3Accepted1/13ms2404 KiB
4Accepted1/13ms2588 KiB
5Accepted1/13ms2552 KiB
6Accepted1/13ms2688 KiB
7Accepted1/13ms2872 KiB
8Accepted1/13ms2960 KiB
9Accepted2/23ms3384 KiB
10Accepted2/24ms3508 KiB
11Accepted2/24ms3796 KiB
12Accepted2/214ms4904 KiB
13Accepted2/232ms6132 KiB
14Accepted2/2140ms12092 KiB
15Accepted1/1179ms17128 KiB
16Accepted1/1150ms13228 KiB
17Accepted2/2199ms17072 KiB
18Accepted2/2181ms16348 KiB
19Accepted2/2192ms16708 KiB
20Accepted2/2192ms17384 KiB
21Accepted2/2203ms17508 KiB