#include <stdio.h> #include <stdlib.h> struct _node{ int value; struct _node* next; }; typedef struct _node Node; void insert_node(Node* array[], int idx, int value) { Node* p; p = (Node*)malloc(sizeof(Node)); p->value = value; if(array[idx]==NULL) { p->next = NULL; array[idx] = p; } else { p->next = array[idx]; array[idx] = p; } } int count_sum(Node* head) { int sum=0; while(head) { sum+=head->value; head=head->next; } return sum; } /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { int n = 10, edges = 8, query = 2, idx, value,sum; scanf("%d %d %d",&n,&edges,&query); Node * array[n+1]; int i=0,j=0; for(i=0;i<n+1;i++) { array[i]=NULL; } for(i=0;i<edges;i++) { scanf("%d %d", &idx, &value); insert_node(array, idx, value); insert_node(array, value, idx); } sum=0; for(i=0;i<query;i++) { scanf("%d",&idx); sum+=count_sum(array[idx]); } printf("%d",sum); return 0; }