51392023-04-20 02:48:13SleepyOverlordAdószedőcpp17Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base30/30
1Elfogadva0/03ms1812 KiB
2Elfogadva0/0165ms11788 KiB
3Elfogadva1/13ms2404 KiB
4Elfogadva1/13ms2588 KiB
5Elfogadva1/13ms2552 KiB
6Elfogadva1/13ms2688 KiB
7Elfogadva1/13ms2872 KiB
8Elfogadva1/13ms2960 KiB
9Elfogadva2/23ms3384 KiB
10Elfogadva2/24ms3508 KiB
11Elfogadva2/24ms3796 KiB
12Elfogadva2/214ms4904 KiB
13Elfogadva2/232ms6132 KiB
14Elfogadva2/2140ms12092 KiB
15Elfogadva1/1179ms17128 KiB
16Elfogadva1/1150ms13228 KiB
17Elfogadva2/2199ms17072 KiB
18Elfogadva2/2181ms16348 KiB
19Elfogadva2/2192ms16708 KiB
20Elfogadva2/2192ms17384 KiB
21Elfogadva2/2203ms17508 KiB