# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
863421 |
2023-10-20T08:07:46 Z |
maks007 |
Paths (BOI18_paths) |
C++14 |
|
3000 ms |
25336 KB |
// Bismi Allah
#include "bits/stdc++.h"
using namespace std;
#define int long long
void do_another(int n, int m, int k, int ans) {
int changes = 1;
vector <int> color(n), g[n], used(n), permutation(k);
set <int> colorUsed;
function <void(int, int)> dfs=[&](int v, int cur) {
if(cur >= changes) {
ans++;
}
if(cur == permutation.size() - 1) return;
used[v] = 1;
for(auto u : g[v] ) {
if(!used[u] && color[u] == permutation[cur+1]) dfs(u, cur + 1);
}
used[v]=0;
};
for(int i = 0; i < n; i ++) cin >> color[i];
for(int i = 0; i < m; i ++) {
int u, v;
cin >> u >> v;
u --, v --;
g[u].push_back(v);
g[v].push_back(u);
}
vector <int> prev;
for(int i = 0; i < k; i ++) permutation[i] = i + 1;
do{
if(prev.size() > 0) {
for(int i = 0; i < permutation.size(); i ++) {
if(prev[i] != permutation[i]) {
changes = i;
break;
}
}
changes = max(changes, 1LL);
}
for(int i = 0; i < n; i ++) {
if(color[i] == permutation[0]) dfs(i, 0);
}
prev = permutation;
} while(next_permutation(permutation.begin(), permutation.end()));
cout << ans;
exit(0);
}
signed main () {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m, k, ans = 0;
cin >> n >> m >> k;
if(k > 3) {
do_another(n, m, k, ans);
return 0;
}
vector <int> color(n), g[n];
for(int i = 0; i < n; i ++) cin >> color[i];
for(int i = 0; i < m; i ++) {
int u, v;
cin >> u >> v;
u --, v --;
g[u].push_back(v);
g[v].push_back(u);
}
for(int i = 0; i < n; i ++) {
for(auto u : g[i]) {
if(color[i] != color[u]) ans ++;
}
int color1 = 0, color2 = 0, forOne = -1;
for(auto u : g[i]) {
if(color[u] == color[i]) continue;
if(forOne == -1) {
forOne = color[u];
color1 ++;
}else {
if(forOne == color[u]) color1 ++;
else color2 ++;
}
}
ans += 2 * color1 * color2;
}
cout << ans;
return 0;
}
Compilation message
paths.cpp: In lambda function:
paths.cpp:16:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | if(cur == permutation.size() - 1) return;
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
paths.cpp: In function 'void do_another(long long int, long long int, long long int, long long int)':
paths.cpp:36:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int i = 0; i < permutation.size(); i ++) {
| ~~^~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
7748 KB |
Output is correct |
2 |
Correct |
40 ms |
7504 KB |
Output is correct |
3 |
Correct |
114 ms |
20300 KB |
Output is correct |
4 |
Correct |
69 ms |
9304 KB |
Output is correct |
5 |
Correct |
60 ms |
9296 KB |
Output is correct |
6 |
Correct |
99 ms |
15472 KB |
Output is correct |
7 |
Correct |
134 ms |
20300 KB |
Output is correct |
8 |
Correct |
135 ms |
20836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
47 ms |
7748 KB |
Output is correct |
12 |
Correct |
40 ms |
7504 KB |
Output is correct |
13 |
Correct |
114 ms |
20300 KB |
Output is correct |
14 |
Correct |
69 ms |
9304 KB |
Output is correct |
15 |
Correct |
60 ms |
9296 KB |
Output is correct |
16 |
Correct |
99 ms |
15472 KB |
Output is correct |
17 |
Correct |
134 ms |
20300 KB |
Output is correct |
18 |
Correct |
135 ms |
20836 KB |
Output is correct |
19 |
Correct |
47 ms |
10580 KB |
Output is correct |
20 |
Correct |
42 ms |
9816 KB |
Output is correct |
21 |
Correct |
126 ms |
24776 KB |
Output is correct |
22 |
Correct |
66 ms |
12884 KB |
Output is correct |
23 |
Correct |
59 ms |
12628 KB |
Output is correct |
24 |
Correct |
95 ms |
19444 KB |
Output is correct |
25 |
Correct |
150 ms |
24656 KB |
Output is correct |
26 |
Correct |
150 ms |
25336 KB |
Output is correct |
27 |
Execution timed out |
3051 ms |
9692 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
3082 ms |
2620 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |