Submission #441402

#TimeUsernameProblemLanguageResultExecution timeMemory
441402abc864197532Paths (BOI18_paths)C++17
70 / 100
324 ms20100 KiB
#include <bits/stdc++.h> using namespace std; #define lli long long int #define X first #define Y second #define pb push_back #define eb emplace_back #define mp make_pair #define pii pair<int, int> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define test(args...) abc("[" + string(#args) + "]", args) void abc() {cerr << endl;} template <typename T, typename ...U> void abc(T a, U ...b) { cerr << a << ' ', abc(b...); } template <typename T> void printv(T l, T r) { while (l != r) cout << *l << " \n"[++l == r]; } const int mod = 1e9 + 7, N = 200000; int main () { ios::sync_with_stdio(false); cin.tie(0); int n, m, k; cin >> n >> m >> k; vector <int> color(n, 0); vector <pii> edge; vector <vector <int>> cnt(n, vector <int>(k, 0)); for (int i = 0; i < n; ++i) cin >> color[i], --color[i]; for (int i = 0, u, v; i < m; ++i) { cin >> u >> v, --u, --v; if (color[u] == color[v]) continue; edge.eb(u, v); cnt[u][color[v]]++; cnt[v][color[u]]++; } lli ans = 0; // len = 2 ans += edge.size() * 2; // len = 3; for (pii A : edge) { int u, v; tie(u, v) = A; for (int i = 0; i < k; ++i) if (i != color[v] && i != color[u]) { ans += cnt[u][i] + cnt[v][i]; } } // len = 4 for (pii A : edge) { int u, v; tie(u, v) = A; for (int i = 0; i < k; ++i) for (int j = 0; j < k; ++j) { if (i == j) continue; if (i == color[v] || i == color[u]) continue; if (j == color[v] || j == color[u]) continue; ans += 1ll * cnt[v][i] * cnt[u][j] + 1ll * cnt[v][j] * cnt[u][i]; } } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...