Untitled

 avatar
unknown
plain_text
3 years ago
826 B
3
Indexable
#include<stdio.h>
typedef struct{
    int n,m;
    int A[100][100];
}Graph;

void init_graph(Graph *G, int x){
    int i,j;
    G->n=x;
    for(i=1;i<=G->n;i++){
        for(j=1;j<=G->n;j++){
            G->A[i][j]=0;
        }
    }
}
void add_edge(Graph *G, int x, int y){
    G->A[x][y]=1;
    G->A[y][x]=1;
    G->m++;
}
int count(Graph *G,int x){
    int i,def=0;
    for(i=1;i<=G->n;i++){
        def+=G->A[x][i];
    }
    return def;
}
int main(){
    Graph G;
    int n, m, u, v,  e;
    scanf("%d %d", &n, &m);
    init_graph(&G, n);

    for (e = 0; e < m; e++) {
        scanf("%d %d", &u, &v);
        add_edge(&G, u, v);
    }
    int i, max=-999,num;
    for(i=1;i<=u;i++){
        if(count(&G,i)>max){
            max=count(&G,i);
            num=i;
        }
    }
    printf("%d %d",num,max);
    return 0;
}
Editor is loading...