Skip to content

Instantly share code, notes, and snippets.

@minhkhoablieu
Created March 7, 2020 14:26
Show Gist options
  • Save minhkhoablieu/fed0b7f62c6c5dd12d45108616d48b25 to your computer and use it in GitHub Desktop.
Save minhkhoablieu/fed0b7f62c6c5dd12d45108616d48b25 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]++;
G->A[v][u]++;
}
int main(int argc, const char * argv[]) {
Graph G;
int n, m;
// FILE *f = fopen("/Users/gkkk/C/Lythuyetdothi/Lythuyetdothi/input.inp", "r");
scanf("%d %d", &n, &m);
init_graph(&G, n);
int u, v;
for(int i = 1; i <= m; i++)
{
scanf("%d %d", &u, &v);
add_edge(&G, u, v);
}
for(int i = 1; i <= n; i++)
{
int sum = 0;
for(int j = 1; j <= n; j++)
{
sum += G.A[i][j];
}
printf("%d\n",sum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment