第二题不是判断每个节点的连接数大于等于2不就行了吗 public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i = 0; i < n; i++) { int m1 = sc.nextInt(); int m2 = sc.nextInt(); int [] num = new int[m1]; int j = 0; while(j < m2){ int temp1 = sc.nextInt() - 1; int temp2 = sc.nextInt() - 1; num[temp1] ++; num[temp2] ++; j++; } System.out.println(hasArrived(num)?"Yes":"No"); } } static boolean hasArrived(int[] num){ for (int i :num) { if(i < 2){ return false; } } return true; }
1 3

相关推荐

牛客网
牛客企业服务