# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
522374 |
2022-02-04T17:19:33 Z |
Lobo |
Paths (BOI18_paths) |
C++17 |
|
450 ms |
211224 KB |
#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define maxn 330000
int n, m, k, a[maxn], dp[maxn][40], mark[maxn][40];
vector<int> g[maxn];
int dfs(int u, int mask) {
if(mark[u][mask]) return dp[u][mask];
dp[u][mask] = 1;
mark[u][mask] = 1;
for(auto v : g[u]) {
if((mask&(1<<a[v])) != 0) continue;
dp[u][mask] += dfs(v,mask + (1<<a[v]));
}
return dp[u][mask];
}
void solve() {
cin >> n >> m >> k;
for(int i = 1; i <= n; i++) {
cin >> a[i];
a[i]--;
}
for(int i = 1; i <= m; i++) {
int u, v; cin >> u >> v;
if(a[u] == a[v]) continue;
g[u].pb(v);
g[v].pb(u);
}
int ans = 0;
for(int i = 1; i <= n; i++) {
ans+= dfs(i,(1<<a[i]));
}
cout << ans-n << endl;
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(0);
// freopen("in.in", "r", stdin);
//freopen("out.out", "w", stdout);
int tt = 1;
// cin >> tt;
while(tt--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8012 KB |
Output is correct |
2 |
Correct |
5 ms |
8064 KB |
Output is correct |
3 |
Correct |
5 ms |
8024 KB |
Output is correct |
4 |
Correct |
6 ms |
8012 KB |
Output is correct |
5 |
Correct |
5 ms |
8020 KB |
Output is correct |
6 |
Correct |
5 ms |
8140 KB |
Output is correct |
7 |
Correct |
5 ms |
8092 KB |
Output is correct |
8 |
Correct |
4 ms |
8140 KB |
Output is correct |
9 |
Correct |
5 ms |
8012 KB |
Output is correct |
10 |
Correct |
4 ms |
8012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
19564 KB |
Output is correct |
2 |
Correct |
53 ms |
14732 KB |
Output is correct |
3 |
Correct |
365 ms |
210440 KB |
Output is correct |
4 |
Correct |
95 ms |
34580 KB |
Output is correct |
5 |
Correct |
59 ms |
30432 KB |
Output is correct |
6 |
Correct |
243 ms |
145456 KB |
Output is correct |
7 |
Correct |
360 ms |
210612 KB |
Output is correct |
8 |
Correct |
382 ms |
210884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8012 KB |
Output is correct |
2 |
Correct |
5 ms |
8064 KB |
Output is correct |
3 |
Correct |
5 ms |
8024 KB |
Output is correct |
4 |
Correct |
6 ms |
8012 KB |
Output is correct |
5 |
Correct |
5 ms |
8020 KB |
Output is correct |
6 |
Correct |
5 ms |
8140 KB |
Output is correct |
7 |
Correct |
5 ms |
8092 KB |
Output is correct |
8 |
Correct |
4 ms |
8140 KB |
Output is correct |
9 |
Correct |
5 ms |
8012 KB |
Output is correct |
10 |
Correct |
4 ms |
8012 KB |
Output is correct |
11 |
Correct |
77 ms |
19564 KB |
Output is correct |
12 |
Correct |
53 ms |
14732 KB |
Output is correct |
13 |
Correct |
365 ms |
210440 KB |
Output is correct |
14 |
Correct |
95 ms |
34580 KB |
Output is correct |
15 |
Correct |
59 ms |
30432 KB |
Output is correct |
16 |
Correct |
243 ms |
145456 KB |
Output is correct |
17 |
Correct |
360 ms |
210612 KB |
Output is correct |
18 |
Correct |
382 ms |
210884 KB |
Output is correct |
19 |
Correct |
78 ms |
19592 KB |
Output is correct |
20 |
Correct |
79 ms |
14712 KB |
Output is correct |
21 |
Correct |
384 ms |
210488 KB |
Output is correct |
22 |
Correct |
108 ms |
34716 KB |
Output is correct |
23 |
Correct |
61 ms |
30428 KB |
Output is correct |
24 |
Correct |
273 ms |
145524 KB |
Output is correct |
25 |
Correct |
387 ms |
210536 KB |
Output is correct |
26 |
Correct |
349 ms |
211056 KB |
Output is correct |
27 |
Correct |
88 ms |
17872 KB |
Output is correct |
28 |
Correct |
125 ms |
21368 KB |
Output is correct |
29 |
Correct |
444 ms |
211224 KB |
Output is correct |
30 |
Correct |
310 ms |
113928 KB |
Output is correct |
31 |
Correct |
376 ms |
114744 KB |
Output is correct |
32 |
Correct |
450 ms |
211140 KB |
Output is correct |
33 |
Correct |
6 ms |
8012 KB |
Output is correct |
34 |
Correct |
6 ms |
8088 KB |
Output is correct |
35 |
Correct |
5 ms |
8012 KB |
Output is correct |
36 |
Correct |
5 ms |
8012 KB |
Output is correct |
37 |
Correct |
4 ms |
8012 KB |
Output is correct |
38 |
Correct |
5 ms |
8076 KB |
Output is correct |
39 |
Correct |
5 ms |
8012 KB |
Output is correct |
40 |
Correct |
4 ms |
8140 KB |
Output is correct |
41 |
Correct |
4 ms |
8012 KB |
Output is correct |
42 |
Correct |
4 ms |
8012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8012 KB |
Output is correct |
2 |
Correct |
34 ms |
11280 KB |
Output is correct |
3 |
Correct |
21 ms |
11284 KB |
Output is correct |
4 |
Correct |
100 ms |
75524 KB |
Output is correct |
5 |
Correct |
116 ms |
75436 KB |
Output is correct |
6 |
Correct |
134 ms |
75616 KB |
Output is correct |
7 |
Correct |
25 ms |
11332 KB |
Output is correct |
8 |
Correct |
122 ms |
75596 KB |
Output is correct |
9 |
Correct |
86 ms |
75684 KB |
Output is correct |
10 |
Correct |
104 ms |
76448 KB |
Output is correct |
11 |
Correct |
101 ms |
43076 KB |
Output is correct |
12 |
Correct |
90 ms |
59956 KB |
Output is correct |
13 |
Correct |
88 ms |
43352 KB |
Output is correct |
14 |
Correct |
128 ms |
75672 KB |
Output is correct |
15 |
Correct |
110 ms |
75792 KB |
Output is correct |
16 |
Correct |
5 ms |
8076 KB |
Output is correct |
17 |
Correct |
5 ms |
8140 KB |
Output is correct |
18 |
Correct |
5 ms |
8072 KB |
Output is correct |
19 |
Correct |
5 ms |
8072 KB |
Output is correct |
20 |
Correct |
5 ms |
8140 KB |
Output is correct |
21 |
Correct |
5 ms |
8040 KB |
Output is correct |
22 |
Correct |
5 ms |
8068 KB |
Output is correct |
23 |
Correct |
5 ms |
8036 KB |
Output is correct |
24 |
Correct |
5 ms |
8052 KB |
Output is correct |
25 |
Correct |
4 ms |
8012 KB |
Output is correct |