Submission #934433

# Submission time Handle Problem Language Result Execution time Memory
934433 2024-02-27T10:18:58 Z ind1v Paths (BOI18_paths) C++11
100 / 100
218 ms 73812 KB
#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 time Memory Grader output
1 Correct 3 ms 14680 KB Output is correct
2 Correct 3 ms 14684 KB Output is correct
3 Correct 4 ms 14684 KB Output is correct
4 Correct 3 ms 14684 KB Output is correct
5 Correct 3 ms 14684 KB Output is correct
6 Correct 3 ms 14684 KB Output is correct
7 Correct 3 ms 14684 KB Output is correct
8 Correct 3 ms 14684 KB Output is correct
9 Correct 2 ms 14684 KB Output is correct
10 Correct 3 ms 14680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 23268 KB Output is correct
2 Correct 42 ms 20560 KB Output is correct
3 Correct 209 ms 73304 KB Output is correct
4 Correct 65 ms 26708 KB Output is correct
5 Correct 59 ms 26704 KB Output is correct
6 Correct 129 ms 58760 KB Output is correct
7 Correct 202 ms 73296 KB Output is correct
8 Correct 204 ms 73808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14680 KB Output is correct
2 Correct 3 ms 14684 KB Output is correct
3 Correct 4 ms 14684 KB Output is correct
4 Correct 3 ms 14684 KB Output is correct
5 Correct 3 ms 14684 KB Output is correct
6 Correct 3 ms 14684 KB Output is correct
7 Correct 3 ms 14684 KB Output is correct
8 Correct 3 ms 14684 KB Output is correct
9 Correct 2 ms 14684 KB Output is correct
10 Correct 3 ms 14680 KB Output is correct
11 Correct 50 ms 23268 KB Output is correct
12 Correct 42 ms 20560 KB Output is correct
13 Correct 209 ms 73304 KB Output is correct
14 Correct 65 ms 26708 KB Output is correct
15 Correct 59 ms 26704 KB Output is correct
16 Correct 129 ms 58760 KB Output is correct
17 Correct 202 ms 73296 KB Output is correct
18 Correct 204 ms 73808 KB Output is correct
19 Correct 47 ms 23380 KB Output is correct
20 Correct 39 ms 20564 KB Output is correct
21 Correct 213 ms 73024 KB Output is correct
22 Correct 63 ms 26708 KB Output is correct
23 Correct 61 ms 26708 KB Output is correct
24 Correct 166 ms 58964 KB Output is correct
25 Correct 213 ms 73076 KB Output is correct
26 Correct 200 ms 73812 KB Output is correct
27 Correct 50 ms 20560 KB Output is correct
28 Correct 62 ms 24148 KB Output is correct
29 Correct 217 ms 72936 KB Output is correct
30 Correct 155 ms 51500 KB Output is correct
31 Correct 121 ms 51404 KB Output is correct
32 Correct 218 ms 73076 KB Output is correct
33 Correct 3 ms 14684 KB Output is correct
34 Correct 2 ms 14684 KB Output is correct
35 Correct 3 ms 14684 KB Output is correct
36 Correct 2 ms 14684 KB Output is correct
37 Correct 3 ms 14684 KB Output is correct
38 Correct 2 ms 14684 KB Output is correct
39 Correct 3 ms 14684 KB Output is correct
40 Correct 4 ms 14680 KB Output is correct
41 Correct 3 ms 14684 KB Output is correct
42 Correct 3 ms 14680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14684 KB Output is correct
2 Correct 20 ms 16732 KB Output is correct
3 Correct 16 ms 16620 KB Output is correct
4 Correct 44 ms 35588 KB Output is correct
5 Correct 39 ms 36036 KB Output is correct
6 Correct 67 ms 35420 KB Output is correct
7 Correct 18 ms 16732 KB Output is correct
8 Correct 67 ms 35408 KB Output is correct
9 Correct 51 ms 36056 KB Output is correct
10 Correct 47 ms 36044 KB Output is correct
11 Correct 46 ms 28120 KB Output is correct
12 Correct 55 ms 33364 KB Output is correct
13 Correct 44 ms 28244 KB Output is correct
14 Correct 66 ms 35536 KB Output is correct
15 Correct 70 ms 35420 KB Output is correct
16 Correct 2 ms 14680 KB Output is correct
17 Correct 3 ms 14684 KB Output is correct
18 Correct 3 ms 14684 KB Output is correct
19 Correct 2 ms 14776 KB Output is correct
20 Correct 2 ms 14684 KB Output is correct
21 Correct 2 ms 14684 KB Output is correct
22 Correct 3 ms 14684 KB Output is correct
23 Correct 3 ms 14820 KB Output is correct
24 Correct 3 ms 14684 KB Output is correct
25 Correct 2 ms 14684 KB Output is correct