Submission #934433

#TimeUsernameProblemLanguageResultExecution timeMemory
934433ind1vPaths (BOI18_paths)C++11
100 / 100
218 ms73812 KiB
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; const int K = 6; int n, m, k; int c[N]; int a[N], b[N]; vector<int> g[N]; int adj[N][K], adjadj[N][K][K]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> c[i]; } for (int i = 1; i <= m; i++) { cin >> a[i] >> b[i]; adj[a[i]][c[b[i]]]++; adj[b[i]][c[a[i]]]++; g[a[i]].emplace_back(b[i]); g[b[i]].emplace_back(a[i]); } for (int i = 1; i <= n; i++) { for (int &j : g[i]) { for (int cc = 1; cc <= k; cc++) { adjadj[i][min(c[j], cc)][max(c[j], cc)] += adj[j][cc]; } } } long long ans = 0; if (2 <= k) { for (int i = 1; i <= m; i++) { ans += 2 * (c[a[i]] != c[b[i]]); } } if (3 <= k) { for (int i = 1; i <= n; i++) { for (int c1 = 1; c1 <= k; c1++) { for (int c2 = 1; c2 <= k; c2++) { if (c1 != c2 && c1 != c[i] && c2 != c[i]) { ans += 1LL * adj[i][c1] * adj[i][c2]; } } } } } if (4 <= k) { for (int i = 1; i <= m; i++) { if (c[a[i]] == c[b[i]]) { continue; } for (int c1 = 1; c1 <= k; c1++) { for (int c2 = 1; c2 <= k; c2++) { if (c1 != c2 && c1 != c[a[i]] && c1 != c[b[i]] && c2 != c[a[i]] && c2 != c[b[i]]) { ans += 2LL * adj[a[i]][c1] * adj[b[i]][c2]; } } } } } if (5 <= k) { for (int i = 1; i <= n; i++) { vector<int> col; for (int j = 1; j <= k; j++) { if (j != c[i]) { col.emplace_back(j); } } sort(col.begin(), col.end()); do { if (col[0] < col[1] && col[2] < col[3]) { ans += adjadj[i][col[0]][col[1]] * adjadj[i][col[2]][col[3]]; } } while (next_permutation(col.begin(), col.end())); } } 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...