Skip to content

Instantly share code, notes, and snippets.

@minhkhoablieu
Created March 7, 2020 14:40
Show Gist options
  • Save minhkhoablieu/4af3f5e6cd375cef87bdcce047821c8c to your computer and use it in GitHub Desktop.
Save minhkhoablieu/4af3f5e6cd375cef87bdcce047821c8c to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define MAX_VERTICES 100
typedef struct{
int A[MAX_VERTICES][MAX_VERTICES];
}Graph;
void init_graph(Graph *G, int n)
{
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
G->A[i][j] = 0;
}
}
}
void add_edge(Graph *G, int u, int v)
{
G->A[u][v] = 1;
G->A[v][u] = 1;
}
int main(int argc, const char * argv[]) {
Graph G;
int n;
// FILE *f = fopen("/Users/gkkk/C/Lythuyetdothi/Lythuyetdothi/input.inp", "r");
scanf("%d", &n);
int A[n][n];
init_graph(&G, n);
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
scanf("%d", &A[i-1][j-1]);
}
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
if(A[i-1][j-1] == 1)
{
add_edge(&G, i, j);
}
}
}
int x, y;
scanf("%d %d", &x, &y);
int count = 0;
for(int u = 1; u <= n; u++)
{
if((G.A[x][u] == 1 ) && (G.A[y][u] == 1) )
{
count+=1;
}
}
printf("%d", count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment