import java.util.Arrays;import java.util.Scanner;public class HihoCoder1467 {static String[] time;static String[][] value;static boolean[] has;static int m;static int result = 0;public static void main(String[] args) {Scanner in = new Scanner(System.in);int num = in.nextInt();for (; num > 0; num--) {result = 0;int n = in.nextInt();m = in.nextInt();value = new String[m][2];for (int i = 0; i < m; i++) {value[i][0] = in.next();value[i][1] = in.next();}handle(n, m);if (result > 0) {System.out.println("GOOD");} else {System.out.println("BAD");}}}public static void handle(int n, int m) {has = new boolean[m + 1];time = new String[m];DFS(0);}private static boolean DFS(int i) {if (i > 3 && checkOut()) {result++;}if (i < 4) {for (int z = 0; z < 2; z++) {if(Arrays.asList(time).contains(value[i][z])){time[i] = value[i][z];}DFS(i + 1);time[i] = null;}}return false;}private static boolean checkOut() {for (String v : time) {if (v != null) {String[] a = v.split("");int index = Integer.parseInt(a[2]);if (!has[index]) {has[index] = true;} else {has = new boolean[m + 1];return false;}}}has = new boolean[m + 1];return true;}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。