# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
58712 | 2018-07-19T01:10:05 Z | onjo0127(#1933) | Paths (BOI18_paths) | C++11 | 512 ms | 69356 KB |
#include <bits/stdc++.h> using namespace std; vector<int> adj[300009]; int color[300009], cnt[300009][11]; long long ans; bool vs[300009], c[11]; void go(int now, int lft) { ++ans; if(lft == 0) return; vs[now] = 1; c[color[now]] = 1; for(auto &it : adj[now]) { if(!vs[it] && !c[color[it]]) { go(it, lft - 1); } } vs[now] = 0; c[color[now]] = 0; } int main() { int N, M, K; scanf("%d%d%d",&N,&M,&K); for(int i=1; i<=N; i++) scanf("%d",&color[i]); for(int i=0; i<M; i++) { int u, v; scanf("%d%d",&u,&v); adj[u].push_back(v); adj[v].push_back(u); ++cnt[u][color[v]]; ++cnt[v][color[u]]; } if(K == 1) return !printf("0"); if(N <= 100 && M <= 100 && K <= 4) { for(int i=1; i<=N; i++) go(i, K-1); printf("%lld", ans - N); } else if(N <= 300000 && M <= 300000 && K <= 3) { int tmp = 1 ^ 2 ^ 3; for(int i=1; i<=N; i++) { for(auto &it : adj[i]) { if(color[i] != color[it]) { ++ans; if(K == 3) ans += cnt[it][tmp ^ color[i] ^ color[it]]; } } } printf("%lld", ans); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7416 KB | Output is correct |
2 | Correct | 7 ms | 7416 KB | Output is correct |
3 | Correct | 8 ms | 7580 KB | Output is correct |
4 | Correct | 8 ms | 7580 KB | Output is correct |
5 | Correct | 9 ms | 7580 KB | Output is correct |
6 | Correct | 9 ms | 7696 KB | Output is correct |
7 | Correct | 9 ms | 7696 KB | Output is correct |
8 | Correct | 9 ms | 7696 KB | Output is correct |
9 | Correct | 8 ms | 7696 KB | Output is correct |
10 | Correct | 8 ms | 7696 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 134 ms | 11496 KB | Output is correct |
2 | Correct | 83 ms | 11496 KB | Output is correct |
3 | Correct | 405 ms | 30096 KB | Output is correct |
4 | Correct | 218 ms | 30096 KB | Output is correct |
5 | Correct | 169 ms | 30096 KB | Output is correct |
6 | Correct | 346 ms | 30096 KB | Output is correct |
7 | Correct | 483 ms | 34556 KB | Output is correct |
8 | Correct | 510 ms | 39964 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7416 KB | Output is correct |
2 | Correct | 7 ms | 7416 KB | Output is correct |
3 | Correct | 8 ms | 7580 KB | Output is correct |
4 | Correct | 8 ms | 7580 KB | Output is correct |
5 | Correct | 9 ms | 7580 KB | Output is correct |
6 | Correct | 9 ms | 7696 KB | Output is correct |
7 | Correct | 9 ms | 7696 KB | Output is correct |
8 | Correct | 9 ms | 7696 KB | Output is correct |
9 | Correct | 8 ms | 7696 KB | Output is correct |
10 | Correct | 8 ms | 7696 KB | Output is correct |
11 | Correct | 134 ms | 11496 KB | Output is correct |
12 | Correct | 83 ms | 11496 KB | Output is correct |
13 | Correct | 405 ms | 30096 KB | Output is correct |
14 | Correct | 218 ms | 30096 KB | Output is correct |
15 | Correct | 169 ms | 30096 KB | Output is correct |
16 | Correct | 346 ms | 30096 KB | Output is correct |
17 | Correct | 483 ms | 34556 KB | Output is correct |
18 | Correct | 510 ms | 39964 KB | Output is correct |
19 | Correct | 141 ms | 39964 KB | Output is correct |
20 | Correct | 99 ms | 39964 KB | Output is correct |
21 | Correct | 503 ms | 48884 KB | Output is correct |
22 | Correct | 230 ms | 48884 KB | Output is correct |
23 | Correct | 219 ms | 48884 KB | Output is correct |
24 | Correct | 383 ms | 53724 KB | Output is correct |
25 | Correct | 481 ms | 64044 KB | Output is correct |
26 | Correct | 512 ms | 69356 KB | Output is correct |
27 | Incorrect | 90 ms | 69356 KB | Output isn't correct |
28 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 69356 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |