Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.*;
- public class Solution {
- public static void main(String[] args) throws IOException {
- Scanner scanner = new Scanner(new File("input.txt"));
- PrintWriter writer = new PrintWriter(new FileOutputStream("output.txt"));
- final int count = 7;
- int N = scanner.nextInt();
- boolean [] visited = new boolean[count];
- @SuppressWarnings("unchecked")
- List<Integer>[] list = new List[count];
- for (int i = 0; i < count; i++)
- list[i] = new ArrayList<Integer>();
- int v, w;
- for (int i = 0; i < N; i++)
- {
- v = scanner.nextInt();
- w = scanner.nextInt();
- if(v != w)
- {
- list[v].add(w);
- list[w].add(v);
- }
- }
- boolean flag = true;
- for(int i = 0; i < count; i++)
- {
- if ( !(list[i].size() % 2 == 0))
- {
- flag = false;
- break;
- }
- }
- if ( flag == false)
- writer.print("No");
- else {
- Queue <Integer> queue = new LinkedList<>();
- for (int i = 0; i < count; i++)
- {
- if (visited[i] == false)
- {
- visited[i] = true;
- queue.add(i);
- while (!queue.isEmpty())
- {
- int u = queue.peek();
- queue.poll();
- for (int j = 0; j < list[u].size(); j++)
- {
- int p = list[u].get(j);
- if(visited[p]) continue;
- queue.add(p);
- visited[p] = true;
- }
- }
- }
- }
- for (Boolean b : visited)
- {
- if ( b == false)
- {
- flag = false;
- break;
- }
- }
- if (flag == false)
- {
- writer.print("No");
- }
- else {
- writer.print("Yes");
- }
- }
- writer.flush();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement