67462023-12-18 17:04:36999Adószedőcpp17Accepted 30/30579ms32196 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;

int main() {
	int N,M,strNODE; cin >> N >> M >> strNODE;
	vector<vector<int>> v(N+1);
	for(int i = 1; i <= M; i++) {
		int a,b;
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	vector<int> ut(N+1,-1);
	map<pair<int,int>, bool> m;
	queue<int> q;
	q.push(strNODE);
	while(!q.empty()){
		int temp=q.front();
		q.pop();
		for(int n : v[temp]){
			if(ut[n]==-1){
				ut[n]=ut[temp]+1;
				q.push(n);
			}
			if(ut[temp]==ut[n]+1)m[make_pair(n,temp)]=true;
		}
	}
	cout<<m.size()<<endl;
	for(auto ans : m){
		cout<<ans.first.second<<' '<<ans.first.first<<endl;
	}
}
SubtaskSumTestVerdictTimeMemory
base30/30
1Accepted0/03ms1816 KiB
2Accepted0/0342ms25648 KiB
3Accepted1/13ms2180 KiB
4Accepted1/13ms2180 KiB
5Accepted1/13ms2572 KiB
6Accepted1/13ms2696 KiB
7Accepted1/13ms2752 KiB
8Accepted1/13ms2800 KiB
9Accepted2/24ms3028 KiB
10Accepted2/26ms3184 KiB
11Accepted2/28ms3380 KiB
12Accepted2/228ms5128 KiB
13Accepted2/275ms7944 KiB
14Accepted2/2391ms22868 KiB
15Accepted1/1500ms29232 KiB
16Accepted1/1467ms25296 KiB
17Accepted2/2538ms31644 KiB
18Accepted2/2579ms29188 KiB
19Accepted2/2476ms30924 KiB
20Accepted2/2388ms31548 KiB
21Accepted2/2485ms32196 KiB