你要的java package 笔试测试; import java.util.*; public class 网易互娱2 {     public static void main(String[] args) {         Scanner sc = new Scanner(System.in);         while (sc.hasNextInt()) {             int n = sc.nextInt();             for (int i = 0; i < n; i++) {                 boolean falg = true;                 int m = sc.nextInt();                 Map<Integer, ArrayList<Integer>> map = new HashMap<>();                 ArrayList<Integer> arr2 = new ArrayList<>();                 for (int k = 0; k < m; k++)                     arr2.add(k);                 for (int j = 0; j < m; j++) {                     ArrayList<Integer> arr3 = new ArrayList<>();                     arr3.add(sc.nextInt());                     int num1 = sc.nextInt(), num2 = sc.nextInt();                     arr2.remove((Object) num1);                     arr2.remove((Object) num2);                     arr3.add(num1);                     arr3.add(num2);                     map.put(j, arr3);                 }                 int head = arr2.get(0);                 //                 Queue<Integer> q = new LinkedList<>();                 q.add(head);                 int beNum = 1, nextNum = 0;// 前后排的个数                 int beVal = map.get(head).get(0), nextVal = 0;                 while ( ! q.isEmpty() )                  {                     while (beNum > 0)                      {                                                  int num3 = q.poll();                         beNum--;                         for (int u = 1; u <= 2; u++)                          {                             int num4 = map.get(num3).get(u);                             if (num4 != -1)                              {                                 q.offer(num4);                                 nextVal += map.get(num4).get(0);                                 nextNum += 1;                             }                         }                     }                     if (beVal >= nextVal && !q.isEmpty() )                      {                         System.out.println("NO");                         falg = false;                         break;                     }                     beNum = nextNum;                     beVal = nextVal;                     nextNum = 0;                     nextVal = 0;                 }                 if (beNum == 0 && falg )                     System.out.println("YES");             }         }     } }
点赞 评论

相关推荐

千千倩倩:简历问题有点多,加v细聊
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务