# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1111703 |
2024-11-12T17:02:07 Z |
PagodePaiva |
Paths (BOI18_paths) |
C++17 |
|
465 ms |
122956 KB |
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 300010;
int n,m, k;
vector <int> g[N];
int cor[N];
int res = 0;
int dp[N][6];
int dp2[N][6][6];
void solve(int x){
if(x == 2){
int t = 0;
for(int i = 1;i <= n;i++){
for(auto x : g[i]){
if(cor[x] != cor[i]) t++;
}
}
res += t;
return;
}
if(x == 3){
for(int v = 1;v <= n;v++){
int resp = 0;
for(auto x : g[v]){
if(cor[x] == cor[v]) continue;
for(int j = 1;j <= k;j++){
if(j == cor[x] or j == cor[v]) continue;
resp += dp[v][j];
}
}
res += resp;
}
return;
}
if(x == 4){
for(int v = 1;v <= n;v++){
int resp = 0;
for(auto x : g[v]){
if(cor[x] == cor[v]) continue;
for(int j = 1;j <= k;j++){
if(cor[x] == j or cor[v] == j) continue;
for(int t = 1;t <= k;t++){
if(cor[x] == t or cor[v] == t or j == t) continue;
resp += dp[v][j]*dp[x][t];
}
}
}
res += resp;
}
}
if(x == 5){
// << res << '\n';
for(int v = 1;v <= n;v++){
for(int j = 1;j <= k;j++){
if(j == cor[v]) continue;
for(int t = 1;t <= k;t++){
if(j == t or t == cor[v])continue;
set <int> s;
s.insert(1);
s.insert(2);
s.insert(3);
s.insert(4);
s.insert(5);
s.erase(j);
s.erase(t);
s.erase(cor[v]);
auto it = s.begin();
int c1 = *it;
it++;
int c2 = *it;
res += dp2[v][j][t]*(dp2[v][c1][c2] + dp2[v][c2][c1]);
}
}
// cout << res << '\n';
}
}
}
int32_t main(){
cin >> n >> m >> k;
for(int i = 1;i <= n;i++){
cin >> cor[i];
}
for(int i = 0;i < m;i++){
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
for(int i = 1;i <= n;i++){
int v = i;
for(auto x : g[v]){
dp[v][cor[x]]++;
}
}
for(int i = 1;i <= n;i++){
int v = i;
for(auto x : g[v]){
int c1 = cor[x];
if(cor[x] == cor[v]) continue;
for(int j = 1;j <= k;j++){
if(j == cor[v] or j == c1) continue;
dp2[v][c1][j] += dp[x][j];
}
}
}
for(int i = 2;i <= k;i++){
solve(i);
//cout << "resposta de i:" << res << '\n';
}
cout << res << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7504 KB |
Output is correct |
2 |
Correct |
5 ms |
7504 KB |
Output is correct |
3 |
Correct |
7 ms |
7672 KB |
Output is correct |
4 |
Correct |
5 ms |
7504 KB |
Output is correct |
5 |
Correct |
5 ms |
7504 KB |
Output is correct |
6 |
Correct |
6 ms |
7516 KB |
Output is correct |
7 |
Correct |
5 ms |
7504 KB |
Output is correct |
8 |
Correct |
5 ms |
7504 KB |
Output is correct |
9 |
Correct |
5 ms |
7268 KB |
Output is correct |
10 |
Correct |
5 ms |
7504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
16724 KB |
Output is correct |
2 |
Correct |
96 ms |
15796 KB |
Output is correct |
3 |
Correct |
344 ms |
118856 KB |
Output is correct |
4 |
Correct |
142 ms |
17568 KB |
Output is correct |
5 |
Correct |
150 ms |
17156 KB |
Output is correct |
6 |
Correct |
272 ms |
84152 KB |
Output is correct |
7 |
Correct |
380 ms |
122956 KB |
Output is correct |
8 |
Correct |
357 ms |
119368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7504 KB |
Output is correct |
2 |
Correct |
5 ms |
7504 KB |
Output is correct |
3 |
Correct |
7 ms |
7672 KB |
Output is correct |
4 |
Correct |
5 ms |
7504 KB |
Output is correct |
5 |
Correct |
5 ms |
7504 KB |
Output is correct |
6 |
Correct |
6 ms |
7516 KB |
Output is correct |
7 |
Correct |
5 ms |
7504 KB |
Output is correct |
8 |
Correct |
5 ms |
7504 KB |
Output is correct |
9 |
Correct |
5 ms |
7268 KB |
Output is correct |
10 |
Correct |
5 ms |
7504 KB |
Output is correct |
11 |
Correct |
118 ms |
16724 KB |
Output is correct |
12 |
Correct |
96 ms |
15796 KB |
Output is correct |
13 |
Correct |
344 ms |
118856 KB |
Output is correct |
14 |
Correct |
142 ms |
17568 KB |
Output is correct |
15 |
Correct |
150 ms |
17156 KB |
Output is correct |
16 |
Correct |
272 ms |
84152 KB |
Output is correct |
17 |
Correct |
380 ms |
122956 KB |
Output is correct |
18 |
Correct |
357 ms |
119368 KB |
Output is correct |
19 |
Correct |
116 ms |
18608 KB |
Output is correct |
20 |
Correct |
96 ms |
16144 KB |
Output is correct |
21 |
Correct |
356 ms |
118856 KB |
Output is correct |
22 |
Correct |
142 ms |
20040 KB |
Output is correct |
23 |
Correct |
123 ms |
17164 KB |
Output is correct |
24 |
Correct |
274 ms |
83640 KB |
Output is correct |
25 |
Correct |
381 ms |
122576 KB |
Output is correct |
26 |
Correct |
367 ms |
122444 KB |
Output is correct |
27 |
Correct |
121 ms |
15764 KB |
Output is correct |
28 |
Correct |
140 ms |
20052 KB |
Output is correct |
29 |
Correct |
465 ms |
118856 KB |
Output is correct |
30 |
Correct |
283 ms |
66488 KB |
Output is correct |
31 |
Correct |
293 ms |
70076 KB |
Output is correct |
32 |
Correct |
418 ms |
119116 KB |
Output is correct |
33 |
Correct |
6 ms |
7504 KB |
Output is correct |
34 |
Correct |
6 ms |
7504 KB |
Output is correct |
35 |
Correct |
8 ms |
7672 KB |
Output is correct |
36 |
Correct |
6 ms |
7672 KB |
Output is correct |
37 |
Correct |
6 ms |
7276 KB |
Output is correct |
38 |
Correct |
6 ms |
7672 KB |
Output is correct |
39 |
Correct |
6 ms |
7504 KB |
Output is correct |
40 |
Correct |
6 ms |
7380 KB |
Output is correct |
41 |
Correct |
6 ms |
7504 KB |
Output is correct |
42 |
Correct |
6 ms |
7504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7504 KB |
Output is correct |
2 |
Correct |
63 ms |
9800 KB |
Output is correct |
3 |
Correct |
41 ms |
9760 KB |
Output is correct |
4 |
Correct |
103 ms |
44652 KB |
Output is correct |
5 |
Correct |
93 ms |
44988 KB |
Output is correct |
6 |
Correct |
356 ms |
44616 KB |
Output is correct |
7 |
Correct |
41 ms |
10312 KB |
Output is correct |
8 |
Correct |
124 ms |
44596 KB |
Output is correct |
9 |
Correct |
93 ms |
44988 KB |
Output is correct |
10 |
Correct |
95 ms |
44732 KB |
Output is correct |
11 |
Correct |
156 ms |
26792 KB |
Output is correct |
12 |
Correct |
237 ms |
35808 KB |
Output is correct |
13 |
Correct |
149 ms |
26936 KB |
Output is correct |
14 |
Correct |
283 ms |
44676 KB |
Output is correct |
15 |
Correct |
269 ms |
44576 KB |
Output is correct |
16 |
Correct |
5 ms |
7504 KB |
Output is correct |
17 |
Correct |
5 ms |
7504 KB |
Output is correct |
18 |
Correct |
5 ms |
7504 KB |
Output is correct |
19 |
Correct |
5 ms |
7504 KB |
Output is correct |
20 |
Correct |
5 ms |
7504 KB |
Output is correct |
21 |
Correct |
5 ms |
7676 KB |
Output is correct |
22 |
Correct |
6 ms |
7504 KB |
Output is correct |
23 |
Correct |
6 ms |
7504 KB |
Output is correct |
24 |
Correct |
5 ms |
7504 KB |
Output is correct |
25 |
Correct |
5 ms |
7504 KB |
Output is correct |