Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Main {
- Scanner in;
- PrintWriter out;
- private void run() {
- in = new Scanner(System.in);
- out = new PrintWriter(System.out);
- try {
- solve();
- } finally {
- out.close();
- }
- }
- class Prize {
- People buyer;
- Prize(People buyer) {
- this.buyer = buyer;
- }
- }
- class People {
- Queue<Prize> queue = new ArrayDeque<>();
- int id;
- People(int id) {
- this.id = id;
- }
- boolean hasPrize() {
- return !queue.isEmpty();
- }
- }
- private void solve() {
- int nTests = in.nextInt();
- for (int t = 1; t <= nTests; t++) {
- int nPeoples = in.nextInt();
- People people[] = new People[nPeoples];
- for (int i = 0; i < people.length; i++) {
- people[i] = new People(i + 1);
- }
- int nMoves = in.nextInt();
- for (int move = 1; move <= nMoves; move++) {
- People from = people[in.nextInt() - 1];
- People to = people[in.nextInt() - 1];
- Prize gift;
- if (from.hasPrize()) {
- gift = from.queue.poll();
- } else {
- gift = new Prize(from);
- }
- if (gift.buyer == to) {
- out.println("YES");
- } else {
- out.println("NO");
- }
- to.queue.add(gift);
- }
- }
- }
- public static void main(String[] args) {
- new Main().run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement