Submission #1347012

#TimeUsernameProblemLanguageResultExecution timeMemory
1347012killerzaluuPaths (BOI18_paths)C++20
20 / 100
106 ms17676 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m, k;
    cin >> n >> m >> k;

    int c[n + 1];
    for (int i = 1; i <= n; i++) cin >> c[i];

    vector<int> g[n + 1];
    long long ans = 0;

    for (int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);

        if (c[a] != c[b]) ans += 2;
    }

    for (int x = 1; x <= n; x++) {
        long long cnt[4] = {};
        for (int u : g[x]) cnt[c[u]]++;

        long long s = 0;
        long long sq = 0;
        for (int col = 1; col <= k; col++) {
            if (col == c[x]) continue;
            s += cnt[col];
            sq += cnt[col] * cnt[col];
        }

        ans += s * s - sq;
    }

    cout << ans << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...