Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- main(){
- int nodeAmount; /* 0 < N < 1000 */
- int edgeAmount; /* 0 < M < 20000*/
- int quesAmount; /* 0 < Q < 2000 */
- int nodeA, nodeB;
- int **ptr2 = NULL;
- int target;
- int cnt, index;
- long long int sum;
- while ( scanf("%d %d %d", &nodeAmount, &edgeAmount, &quesAmount)!=EOF ){
- ptr2 = (int**)malloc((nodeAmount+1) * sizeof(int*));
- for ( cnt=0 ; cnt<=nodeAmount ; cnt++ )
- ptr2[cnt] = (int*)malloc((nodeAmount+1) * sizeof(int));
- for ( cnt=0 ; cnt<edgeAmount ; cnt++ ){
- scanf("%d %d", &nodeA, &nodeB);
- ptr2[nodeA][nodeB] = 1;
- ptr2[nodeB][nodeA] = 1;
- }
- for ( cnt=0, sum=0 ; cnt<quesAmount ; cnt++ ){
- scanf("%d", &target);
- for ( index=1 ; index<=nodeAmount ; index++ )
- if ( ptr2[target][index]==1 )
- sum += index;
- }
- printf("%lld\n", sum);
- for (cnt=0 ; cnt<=nodeAmount ; cnt++ )
- free(ptr2[cnt]);
- free(ptr2);
- } /* END while */
- system("PAUSE");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement