Advertisement
vov44k

479

Jan 26th, 2023
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) throws IOException {
  8.         Scanner in = new Scanner(new File("input.txt"));
  9.         PrintWriter pw = new PrintWriter("output.txt");
  10.  
  11.         int n = in.nextInt();
  12.         int m = in.nextInt();
  13.         int [][] matrix = new int [n][n];
  14.  
  15.         for (int i = 0; i < m; i++) {
  16.             int a = in.nextInt() - 1;
  17.             int b = in.nextInt() - 1;
  18.             matrix[a][b] = 1;
  19.             matrix[b][a] = 1;
  20.         }
  21.         for (int i = 0; i < n; i++){
  22.             for (int j = i + 1; j < n; j++){
  23.                 for (int k = j + 1; k < n; k++){
  24.                     if(matrix[i][j] + matrix[j][k] + matrix[k][i] == 2){
  25.                         pw.print("NO");
  26.                         pw.close();
  27.                         return;
  28.                     }
  29.                 }
  30.             }
  31.         }
  32.         pw.print("YES");
  33.         pw.close();
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement