結果

問題 No.630 門松グラフ
ユーザー uafr_csuafr_cs
提出日時 2018-01-05 22:42:50
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,770 bytes
コンパイル時間 2,521 ms
コンパイル使用メモリ 85,980 KB
実行使用メモリ 63,616 KB
最終ジャッジ日時 2023-08-24 21:01:12
合計ジャッジ時間 13,937 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 172 ms
56,680 KB
testcase_01 AC 120 ms
56,260 KB
testcase_02 AC 122 ms
56,012 KB
testcase_03 AC 188 ms
56,876 KB
testcase_04 AC 124 ms
55,436 KB
testcase_05 AC 121 ms
55,656 KB
testcase_06 AC 123 ms
55,844 KB
testcase_07 AC 141 ms
56,144 KB
testcase_08 AC 173 ms
55,136 KB
testcase_09 AC 121 ms
55,712 KB
testcase_10 AC 121 ms
55,788 KB
testcase_11 AC 138 ms
55,860 KB
testcase_12 WA -
testcase_13 AC 120 ms
55,464 KB
testcase_14 WA -
testcase_15 AC 138 ms
56,008 KB
testcase_16 AC 177 ms
57,192 KB
testcase_17 WA -
testcase_18 AC 172 ms
56,752 KB
testcase_19 AC 176 ms
57,228 KB
testcase_20 AC 1,065 ms
63,616 KB
testcase_21 AC 120 ms
56,096 KB
testcase_22 AC 1,096 ms
63,308 KB
testcase_23 AC 122 ms
55,580 KB
testcase_24 WA -
testcase_25 AC 128 ms
56,524 KB
testcase_26 WA -
testcase_27 AC 770 ms
62,644 KB
testcase_28 AC 128 ms
53,760 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int M = sc.nextInt();
		
		if(M < N - 1){ System.out.println("NO"); return; }
		if(N == 3){
			if(M >= 3){ System.out.println("NO"); return; }
			if(M == 2){
				System.out.println("YES");
				System.out.println("1 3 2");
				System.out.println("1 2");
				System.out.println("2 3");
				return;
			}
		}
		if(M == N - 1){
			System.out.println("YES");
			System.out.print(100000);
			for(int i = 1; i < N; i++){
				System.out.print(" " + i);
			}
			System.out.println();
			for(int i = 1; i < N; i++){
				System.out.println(1 + " " + (i + 1));
			}
			
			return;
		}
		
		final int evenN = N / 2 * 2;
		final int evenM = ((evenN == N) ? M : M - 1) - evenN;
		int current_max = 100000;
		int current_min = 1;
		int[] as = new int[N];
		
		if(evenN != N){ as[N - 1] = current_max--; }
		for(int i = 0; i < evenN; i++){
			as[i] = i % 2 == 0 ? (current_min++) : (current_max--); 
		}
		//System.out.println(Arrays.toString(as));
		//System.out.println(evenM);
		
		int edge_count = 0;
		for(int start = 0; start < evenN && edge_count < evenM; start++){
			int curr = start;
			while(true){
				final int to = ((curr == start) ? curr + 3 : curr + 2) % evenN;
				final int to_next = (to + 1) % evenN;
				
				if(to_next == start){ break; }
				if(to < start){ break; }
				
				//System.out.println(start + " " + curr + " " + to);
				edge_count++;
				curr = to;
			}
		}
		
		if(edge_count != evenM){
			System.out.println("NO");
			return;
		}
		
		System.out.println("YES");
		for(int i = 0; i < N; i++){
			System.out.print((i == 0 ? "" : " ") + as[i]);
		}
		System.out.println();
		for(int i = 0; i < evenN; i++){
			final int from = i;
			final int to = (i + 1) % evenN;
			
			System.out.println(Math.min(from + 1, to + 1) + " " + Math.max(from + 1, to + 1));
			//System.out.println((from + 1) + " " + (to + 1));
		}
		if(evenN != N){ System.out.println(1 + " " + N); }
		
		edge_count = 0;
		for(int start = 0; start < evenN && edge_count < evenM; start++){
			int curr = start;
			while(true){
				final int to = ((curr == start) ? curr + 3 : curr + 2) % evenN;
				final int to_next = (to + 1) % evenN;
				
				if(to_next == start){ break; }
				if(to < start){ break; }
				
				System.out.println((start + 1) + " " + (to + 1));
				//System.out.println(start + " " + curr + " " + to);
				edge_count++;
				curr = to;
			}
		}
	}
}
0