提出 #71367625


ソースコード 拡げる

#include<bits/stdc++.h>
#define cmin(a,b) a=std::min(a,b)
#define cmax(a,b) a=std::max(a,b)
#define inf
#define mod
#define maxn 300005
#define int long long
int n,m,to1[maxn],to2[maxn];
std::vector<int> to[maxn];
std::map<int,int> mp[maxn];
std::queue<int> que;
int vis1[maxn],vis2[maxn];
signed main(){
	scanf("%lld%lld",&n,&m);
	for(int i=1,u,v;i<=m;i++){
		scanf("%lld%lld",&u,&v);
		to[u].push_back(v);
		to[v].push_back(u);
	}
	for(int i=1;i<=n;i++){
		std::sort(to[i].begin(),to[i].end());
	}
	que.push(1),vis1[1]=1;
	while(!que.empty()){
		int x=que.front();que.pop();
		for(int v:to[x]){
			if(vis1[v]) continue;
			vis1[v]=1,to1[v]=x,que.push(v);
			mp[x][v]=1;
		}
	}
	for(int i=1;i<=n;i++){
		std::sort(to[i].begin(),to[i].end(),std::greater<int>());
	}
	que.push(2),vis2[2]=1;
	int cnt=0;
	while(!que.empty()){
		int x=que.front();que.pop();cnt++;
		for(int v:to[x]){
			if(vis2[v]||mp[x][v]) continue;
			vis2[v]=1,to2[v]=x,que.push(v);
		}
	}
	if(cnt!=n){
		puts("No");
	}else{
		puts("Yes");
		printf("%lld\n%lld\n",to2[1],to1[2]);
		for(int i=3;i<=n;i++){
			printf("%lld %lld\n",to1[i],to2[i]); 
		}
	}
	return 0;
}
/*

*/

提出情報

提出日時
問題 D - Michishirube
ユーザ huanghongjun
言語 C++23 (GCC 15.2.0)
得点 0
コード長 1200 Byte
結果 WA
実行時間 166 ms
メモリ 59084 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 700
結果
AC × 2
AC × 16
WA × 26
セット名 テストケース
Sample 00-sample-001.txt, 00-sample-002.txt
All 00-sample-001.txt, 00-sample-002.txt, 01-non_bridge_yes-001.txt, 01-non_bridge_yes-002.txt, 01-non_bridge_yes-003.txt, 01-non_bridge_yes-004.txt, 01-non_bridge_yes-005.txt, 02-less_bridge_yes-001.txt, 02-less_bridge_yes-002.txt, 02-less_bridge_yes-003.txt, 02-less_bridge_yes-004.txt, 02-less_bridge_yes-005.txt, 02-less_bridge_yes-006.txt, 02-less_bridge_yes-007.txt, 02-less_bridge_yes-008.txt, 02-less_bridge_yes-009.txt, 02-less_bridge_yes-010.txt, 03-many_bridge_yes-001.txt, 03-many_bridge_yes-002.txt, 03-many_bridge_yes-003.txt, 03-many_bridge_yes-004.txt, 03-many_bridge_yes-005.txt, 03-many_bridge_yes-006.txt, 03-many_bridge_yes-007.txt, 03-many_bridge_yes-008.txt, 03-many_bridge_yes-009.txt, 03-many_bridge_yes-010.txt, 04-small_yes-001.txt, 04-small_yes-002.txt, 04-small_yes-003.txt, 04-small_yes-004.txt, 04-small_yes-005.txt, 05-no-001.txt, 05-no-002.txt, 05-no-003.txt, 05-no-004.txt, 05-no-005.txt, 05-no-006.txt, 05-no-007.txt, 05-no-008.txt, 05-no-009.txt, 05-no-010.txt
ケース名 結果 実行時間 メモリ
00-sample-001.txt AC 9 ms 17952 KiB
00-sample-002.txt AC 9 ms 17812 KiB
01-non_bridge_yes-001.txt WA 94 ms 46848 KiB
01-non_bridge_yes-002.txt WA 91 ms 46156 KiB
01-non_bridge_yes-003.txt WA 85 ms 45740 KiB
01-non_bridge_yes-004.txt WA 95 ms 43128 KiB
01-non_bridge_yes-005.txt WA 85 ms 45124 KiB
02-less_bridge_yes-001.txt WA 100 ms 48340 KiB
02-less_bridge_yes-002.txt WA 93 ms 46036 KiB
02-less_bridge_yes-003.txt WA 99 ms 48404 KiB
02-less_bridge_yes-004.txt WA 96 ms 46404 KiB
02-less_bridge_yes-005.txt WA 91 ms 46124 KiB
02-less_bridge_yes-006.txt WA 101 ms 48192 KiB
02-less_bridge_yes-007.txt WA 103 ms 48504 KiB
02-less_bridge_yes-008.txt WA 100 ms 47556 KiB
02-less_bridge_yes-009.txt WA 103 ms 48788 KiB
02-less_bridge_yes-010.txt WA 95 ms 46228 KiB
03-many_bridge_yes-001.txt AC 164 ms 58260 KiB
03-many_bridge_yes-002.txt WA 144 ms 59084 KiB
03-many_bridge_yes-003.txt WA 132 ms 52816 KiB
03-many_bridge_yes-004.txt WA 142 ms 54576 KiB
03-many_bridge_yes-005.txt WA 150 ms 58324 KiB
03-many_bridge_yes-006.txt WA 143 ms 55500 KiB
03-many_bridge_yes-007.txt WA 150 ms 59060 KiB
03-many_bridge_yes-008.txt WA 142 ms 54528 KiB
03-many_bridge_yes-009.txt WA 143 ms 57004 KiB
03-many_bridge_yes-010.txt AC 166 ms 58332 KiB
04-small_yes-001.txt AC 9 ms 17920 KiB
04-small_yes-002.txt AC 10 ms 17952 KiB
04-small_yes-003.txt WA 9 ms 17968 KiB
04-small_yes-004.txt WA 9 ms 17812 KiB
04-small_yes-005.txt WA 9 ms 17812 KiB
05-no-001.txt AC 114 ms 49868 KiB
05-no-002.txt AC 123 ms 50464 KiB
05-no-003.txt AC 101 ms 47300 KiB
05-no-004.txt AC 116 ms 51628 KiB
05-no-005.txt AC 111 ms 48212 KiB
05-no-006.txt AC 150 ms 54956 KiB
05-no-007.txt AC 140 ms 54740 KiB
05-no-008.txt AC 117 ms 50732 KiB
05-no-009.txt AC 125 ms 52052 KiB
05-no-010.txt AC 116 ms 52692 KiB