daily pastebin goal
64%
SHARE
TWEET

Untitled

a guest Mar 18th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "graph.c"
  4.  
  5. void pass(int** matrix, int a, int b, int n, int prev, int *k){
  6.     for (int i = 0; i < n; i++){
  7.         if ((matrix[a][i] == 1) && (i != prev)){
  8.             if (i == b) {
  9.                 *k = 1;
  10.             }
  11.             pass(matrix, i, b, n, a, k);
  12.         }
  13.     }
  14. }
  15.  
  16. int main() {
  17.     int ** matrix;
  18.     int n, a, b;
  19.     int q = 0;
  20.     FILE *f;
  21.     f = fopen ("text.txt", "r");
  22.  
  23.     fscanf (f, "%d", &n);
  24.  
  25.     matrix = (int**)malloc(n * sizeof(int*));
  26.     for (int i = 0; i < n; i++) matrix[i] = (int *)malloc(n * sizeof(int));
  27.  
  28.     for (int i = 0; i < n; i++){
  29.         for (int j = 0; j < n; j++){
  30.             fscanf (f, "%d", &matrix[i][j]);
  31.         }
  32.     }
  33.  
  34.     fscanf (f, "%d", &a);
  35.     fscanf (f, "%d", &b);
  36.     pass(matrix, a, b, n - 1, 0, &q);
  37.     if (q == 1) printf("YES\n");
  38.     else printf("NO\n");
  39.     return 0;
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top