# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
95453 | bacegen4o | Paths (BOI18_paths) | C11 | 219 ms | 19704 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
//////////////---------------- baltic paths
int main() {
int n, m, k, a, b;
scanf("%d %d %d", &n, &m, &k);
int colors[n];
vec graph [n]; memset(graph, 0, sizeof(graph));
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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |