Submission #95454

#TimeUsernameProblemLanguageResultExecution timeMemory
95454bacegen4oPaths (BOI18_paths)C11
20 / 100
255 ms15196 KiB
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<assert.h>
#include<stdbool.h>
#include<limits.h>
typedef long long ll;
#define resizeArray(ptr, type, size) ((type*)realloc(ptr, (size) * sizeof(type)))
int *pushback(int *array, int *size, int value) {
    int *output = resizeArray(array, int, *size + 1);
    output[(*size)++] = value;
    return output;
}
typedef struct{
	int*ptr;
	int sz;
}vec;
vec newVec() {
	vec rez;
	rez.ptr = NULL;
	rez.sz  = 0;
	return rez;
}
vec*graph;
int main() {
    int n, m, k, a, b;
    scanf("%d %d %d", &n, &m, &k);
    int colors[n];
    graph = calloc(n, sizeof(vec));
    for(int c1=0; c1<n; c1++){
        scanf("%d", &colors[c1]);
        colors[c1]--;
    }
    for(int c1 = 0; c1 < m; c1++){
        scanf("%d %d", &a, &b);
        a--, b--;
        graph[a].ptr = pushback(graph[a].ptr, &graph[a].sz, b);
        graph[b].ptr = pushback(graph[b].ptr, &graph[b].sz, a);
    }
    ll ans = 0;
    for(int c1=0; c1<n; c1++){
        ll F[3] = {0};
        for(int c2 = 0; c2 < graph[c1].sz; c2++)
            F[colors[graph[c1].ptr[c2]]]++;
        F[colors[c1]] = 0;
        ans += 2*(F[0]*F[1]+F[0]*F[2]+F[1]*F[2])+F[0]+F[1]+F[2];
    }
    printf("%lld\n", ans);
    return 0;
}

Compilation message (stderr)

paths.c: In function 'main':
paths.c:28:5: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &n, &m, &k);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
paths.c:32:9: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &colors[c1]);
         ^~~~~~~~~~~~~~~~~~~~~~~~
paths.c:36:9: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b);
         ^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...