Submission #25425563
Source Code Expand
Copy
import java.util.ArrayDeque;import java.util.ArrayList;import java.util.Arrays;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Queue;import java.util.Scanner;import java.util.stream.IntStream;public class Main {public static void main(String[] args) {try (Scanner scanner = new Scanner(System.in)) {int n = scanner.nextInt(), m = scanner.nextInt();Map<Integer, List<Queue<Integer>>> map = new HashMap<>();Queue<Integer> que = new ArrayDeque<>();int[] count = new int[n];Arrays.fill(count, 0);IntStream.range(0, m).forEach(i -> {int k = scanner.nextInt();
import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Queue; import java.util.Scanner; import java.util.stream.IntStream; public class Main { public static void main(String[] args) { try (Scanner scanner = new Scanner(System.in)) { int n = scanner.nextInt(), m = scanner.nextInt(); Map<Integer, List<Queue<Integer>>> map = new HashMap<>(); Queue<Integer> que = new ArrayDeque<>(); int[] count = new int[n]; Arrays.fill(count, 0); IntStream.range(0, m).forEach(i -> { int k = scanner.nextInt(); Queue<Integer> q = new ArrayDeque<>(); IntStream.range(0, k).forEach(j -> q.add(scanner.nextInt() - 1)); int first = q.peek(); count[first]++; if (count[first] >= 2) { que.add(first); } List<Queue<Integer>> list = map.get(first); if (null == list) { list = new ArrayList<>(); map.put(first, list); } list.add(q); }); while (!que.isEmpty()) { int now = que.poll(); List<Queue<Integer>> nList = map.get(now); for (Queue<Integer> q : nList) { q.poll(); if (!q.isEmpty()) { int first = q.peek(); count[first]++; if (count[first] >= 2) { que.add(first); } List<Queue<Integer>> list = map.get(first); if (null == list) { list = new ArrayList<>(); map.put(first, list); } list.add(q); } } map.remove(now); } System.out.println(map.isEmpty() ? "Yes" : "No"); } } }
Submission Info
Submission Time | |
---|---|
Task | D - Pair of Balls |
User | danielsun3164 |
Language | Java (OpenJDK 11.0.6) |
Score | 400 |
Code Size | 1628 Byte |
Status | AC |
Exec Time | 1613 ms |
Memory | 129160 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0.txt, example1.txt |
All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, example0.txt, example1.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | AC | 165 ms | 35820 KB |
001.txt | AC | 119 ms | 35800 KB |
002.txt | AC | 1541 ms | 117988 KB |
003.txt | AC | 639 ms | 68548 KB |
004.txt | AC | 1543 ms | 118008 KB |
005.txt | AC | 525 ms | 63192 KB |
006.txt | AC | 1606 ms | 115736 KB |
007.txt | AC | 629 ms | 64940 KB |
008.txt | AC | 1525 ms | 115920 KB |
009.txt | AC | 906 ms | 72320 KB |
010.txt | AC | 1582 ms | 120228 KB |
011.txt | AC | 954 ms | 71316 KB |
012.txt | AC | 1547 ms | 115448 KB |
013.txt | AC | 799 ms | 67656 KB |
014.txt | AC | 1613 ms | 120928 KB |
015.txt | AC | 471 ms | 59812 KB |
016.txt | AC | 1487 ms | 128652 KB |
017.txt | AC | 1470 ms | 128860 KB |
018.txt | AC | 812 ms | 71100 KB |
019.txt | AC | 823 ms | 71072 KB |
020.txt | AC | 898 ms | 72464 KB |
021.txt | AC | 1487 ms | 129160 KB |
022.txt | AC | 1393 ms | 119688 KB |
023.txt | AC | 1344 ms | 124884 KB |
024.txt | AC | 1069 ms | 101748 KB |
example0.txt | AC | 119 ms | 35800 KB |
example1.txt | AC | 108 ms | 35824 KB |