QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#23450 | #2470. Šarenlist | Skyowo | 110 ✓ | 11ms | 3796kb | C++14 | 1.9kb | 2022-03-16 13:24:10 | 2022-04-30 03:08:10 |
Judging History
answer
// Skyqwq
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; }
template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; }
template <typename T> void inline read(T &x) {
int f = 1; x = 0; char s = getchar();
while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
x *= f;
}
const int N = 65, P = 1e9 + 7;
int n, m, k, fa[N], d[N], fw[N], f[N];
vector<PII> g[N];
void dfs(int u) {
for (PII o: g[u]) {
int v = o.fi;
if (v == fa[u]) continue;
d[v] = d[u] + 1, fa[v] = u, fw[v] = o.se;
dfs(v);
}
}
vector<int> b[N];
void inline work(int x, int y, int k) {
while (x != y) {
if (d[x] < d[y]) swap(x, y);
b[k].pb(fw[x]);
x = fa[x];
}
}
int find(int x) {
return f[x] == x ? x : f[x] = find(f[x]);
}
void inline add(int &x, int y) {
x += y;
if (x >= P) x -= P;
}
void inline del(int &x, int y) {
x -= y;
if (x < 0) x += P;
}
int main() {
read(n), read(m), read(k);
for (int i = 1, u, v; i < n; i++) {
read(u), read(v);
g[u].pb(mp(v, i)), g[v].pb(mp(u, i));
}
dfs(1);
for (int i = 0; i < m; i++) {
int u, v; read(u), read(v);
work(u, v, i);
}
int ans = 0;
for (int i = 0; i < (1 << m); i++) {
int c = 0;
for (int j = 1; j < n; j++) f[j] = j;
for (int j = 0; j < m; j++) {
if (i >> j & 1) {
for (int k: b[j])
f[find(k)] = find(b[j][0]);
c ^= 1;
}
}
int v = 1;
for (int j = 1; j < n; j++)
if (find(j) == j) v = 1ll * v * k % P;
if (c) del(ans, v);
else add(ans, v);
}
printf("%d\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 4ms
memory: 3724kb
input:
10 1 315293654 7 6 4 6 2 7 1 2 5 1 3 4 8 6 10 7 9 4 9 3
output:
105665210
result:
ok single line: '105665210'
Test #2:
score: 0
Accepted
time: 4ms
memory: 3592kb
input:
20 1 905916093 17 14 9 14 13 9 20 14 2 9 8 14 6 2 11 9 16 14 12 6 19 11 15 13 5 17 4 15 3 2 7 3 18 5 10 12 1 8 2 1
output:
662166712
result:
ok single line: '662166712'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3728kb
input:
30 1 875533734 24 11 23 11 5 24 14 5 15 11 17 15 4 5 3 17 26 11 12 26 8 23 16 23 28 23 1 28 29 3 6 12 20 24 18 8 21 12 13 11 30 26 9 15 25 30 19 29 10 9 27 20 2 23 22 3 7 2 28 4
output:
169123854
result:
ok single line: '169123854'
Test #4:
score: 0
Accepted
time: 3ms
memory: 3676kb
input:
40 1 299177023 37 31 1 31 38 37 14 38 17 14 27 38 23 17 11 14 3 31 19 38 39 19 29 38 22 17 30 27 9 23 21 14 24 21 18 3 25 18 4 30 12 21 40 23 32 40 6 37 16 29 26 17 13 30 8 16 20 8 28 32 34 12 2 31 15 4 33 19 7 37 10 6 36 9 35 37 5 32 22 24
output:
878618072
result:
ok single line: '878618072'
Test #5:
score: 0
Accepted
time: 3ms
memory: 3636kb
input:
50 1 560637843 33 6 46 6 35 6 21 6 30 6 5 30 22 33 50 21 41 46 8 35 24 30 25 30 37 5 14 35 49 5 29 22 27 30 3 29 26 24 45 30 1 22 17 26 15 41 32 41 4 1 44 8 40 8 18 41 23 50 31 25 39 40 47 14 36 17 12 35 11 6 10 18 13 40 20 40 7 47 38 12 28 39 2 39 19 11 9 15 48 5 43 11 34 47 42 13 16 14 25 32
output:
904306543
result:
ok single line: '904306543'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
60 1 126890914 54 4 15 54 31 4 10 54 6 10 21 6 38 54 49 31 19 10 25 21 34 25 9 21 8 15 30 54 60 49 32 21 33 15 58 60 2 60 29 8 26 21 5 32 28 60 11 30 39 19 44 33 36 34 22 9 59 21 56 26 23 6 20 49 1 58 41 60 7 41 42 26 46 4 50 58 40 28 37 10 3 46 27 8 51 9 48 60 18 39 13 59 52 25 53 33 17 7 12 2 43 5...
output:
185898617
result:
ok single line: '185898617'
Subtask #2:
score: 15
Accepted
Test #7:
score: 15
Accepted
time: 3ms
memory: 3708kb
input:
10 2 593210622 6 7 10 6 9 6 5 9 4 10 8 6 3 4 2 9 1 4 3 2 7 9
output:
381858174
result:
ok single line: '381858174'
Test #8:
score: 0
Accepted
time: 3ms
memory: 3668kb
input:
20 2 854727310 5 14 7 14 19 14 20 19 4 5 2 5 18 19 13 2 9 20 10 14 8 7 1 9 16 9 17 16 3 17 15 5 6 16 11 19 12 5 12 6 18 6
output:
908879719
result:
ok single line: '908879719'
Test #9:
score: 0
Accepted
time: 3ms
memory: 3668kb
input:
30 2 731245700 4 16 10 4 25 16 6 25 30 16 13 4 8 4 12 6 21 12 20 21 29 8 3 29 28 16 17 12 19 17 26 3 18 30 27 17 23 17 9 26 14 6 2 28 7 17 22 7 15 16 24 18 1 9 11 17 5 13 16 19 16 17
output:
882433193
result:
ok single line: '882433193'
Test #10:
score: 0
Accepted
time: 3ms
memory: 3744kb
input:
40 2 389940199 25 14 36 14 8 36 26 14 9 8 32 14 13 36 31 25 30 9 20 8 12 14 33 12 6 9 2 26 15 6 29 15 35 31 21 8 34 14 24 35 4 6 11 8 18 30 7 6 19 21 40 11 38 36 39 30 16 40 23 20 22 20 10 2 5 4 3 25 27 14 28 38 1 30 37 23 17 13 7 38 23 1
output:
982185549
result:
ok single line: '982185549'
Test #11:
score: 0
Accepted
time: 3ms
memory: 3724kb
input:
50 2 526847279 39 31 47 31 42 39 19 39 44 47 34 19 22 39 15 31 30 34 2 39 4 34 3 34 45 47 28 30 12 19 49 47 9 39 23 34 16 23 26 42 36 12 17 2 38 26 1 19 5 44 6 44 48 5 24 9 7 28 20 6 21 1 29 21 35 20 10 24 43 49 25 43 33 45 41 10 50 41 32 48 13 2 37 7 11 21 8 37 40 29 14 19 46 42 18 12 27 23 13 35 1...
output:
57096114
result:
ok single line: '57096114'
Test #12:
score: 0
Accepted
time: 3ms
memory: 3712kb
input:
60 2 14354986 34 21 33 34 38 33 59 38 22 38 60 38 45 60 31 38 46 21 44 21 3 33 40 38 32 3 4 40 42 60 55 45 35 42 27 55 51 34 29 60 49 4 36 59 6 55 48 35 11 31 9 4 18 38 14 21 15 45 17 22 56 60 28 11 58 28 12 14 1 14 16 46 23 55 24 38 13 51 26 18 30 51 19 22 7 27 53 26 37 44 52 44 43 7 5 45 8 44 47 3...
output:
915822732
result:
ok single line: '915822732'
Subtask #3:
score: 10
Accepted
Test #13:
score: 10
Accepted
time: 3ms
memory: 3636kb
input:
30 4 140567500 20 8 8 25 25 17 17 10 14 2 2 13 13 9 9 3 3 4 4 15 18 16 16 19 19 26 1 23 23 30 30 21 21 12 12 6 5 21 5 24 30 22 22 15 5 7 14 28 22 11 15 16 22 27 9 25 12 29 20 10 14 15 18 26 1 6
output:
693318126
result:
ok single line: '693318126'
Test #14:
score: 0
Accepted
time: 2ms
memory: 3744kb
input:
35 5 191824744 5 18 18 21 21 7 19 10 10 26 26 34 34 12 12 33 33 9 9 24 24 15 4 23 23 2 2 22 29 13 13 27 17 6 6 11 11 8 8 3 3 30 30 35 35 14 14 25 15 16 16 13 34 5 12 31 12 6 16 20 24 22 31 32 21 1 32 28 5 7 19 15 4 22 29 27 17 25
output:
824689808
result:
ok single line: '824689808'
Test #15:
score: 0
Accepted
time: 3ms
memory: 3676kb
input:
40 5 222977922 39 31 31 34 34 4 4 9 9 12 12 11 11 15 15 1 1 7 36 22 22 10 10 28 28 20 20 37 37 30 30 2 2 14 14 8 8 35 35 21 25 33 33 26 27 19 19 23 23 38 38 16 16 24 17 3 3 29 29 5 5 32 32 6 18 13 13 27 18 36 18 29 18 40 16 25 26 7 39 7 36 21 25 26 27 24 17 6
output:
836258984
result:
ok single line: '836258984'
Test #16:
score: 0
Accepted
time: 2ms
memory: 3744kb
input:
45 8 991191642 24 25 25 4 4 6 6 2 27 18 18 44 39 28 28 16 16 41 41 23 23 7 7 19 19 14 14 29 29 12 12 38 10 42 42 43 8 35 35 20 20 30 21 26 26 36 36 1 32 3 3 37 37 15 15 5 5 33 33 22 31 17 17 13 13 45 34 17 31 8 13 9 30 14 35 22 9 40 34 43 16 44 45 21 34 6 39 11 24 2 27 44 39 38 10 43 8 30 21 1 32 22...
output:
375375713
result:
ok single line: '375375713'
Test #17:
score: 0
Accepted
time: 4ms
memory: 3632kb
input:
50 12 521658754 34 24 24 32 25 8 8 46 3 12 12 7 7 22 22 33 9 19 19 20 20 40 40 50 17 13 13 35 35 29 29 49 49 47 44 21 21 2 18 41 41 38 38 37 43 39 39 36 36 14 28 45 45 16 6 30 30 31 10 48 48 27 27 5 5 26 4 42 42 15 15 1 20 44 2 30 40 22 31 8 44 16 46 11 6 38 44 39 31 48 8 24 25 15 46 23 19 17 34 32 ...
output:
968579174
result:
ok single line: '968579174'
Test #18:
score: 0
Accepted
time: 3ms
memory: 3756kb
input:
55 4 332039590 49 46 46 25 37 41 41 6 6 24 24 13 13 15 15 53 53 45 45 12 12 21 21 4 4 29 29 16 16 11 11 31 31 54 54 5 5 32 32 19 19 10 10 3 3 47 47 52 52 17 17 36 36 48 48 23 23 7 7 26 26 38 38 28 51 42 42 1 1 35 35 34 34 2 2 30 30 40 14 8 8 33 33 22 22 39 39 43 43 55 55 44 44 50 44 20 44 10 37 27 2...
output:
787613256
result:
ok single line: '787613256'
Test #19:
score: 0
Accepted
time: 3ms
memory: 3664kb
input:
60 2 629104177 45 1 1 22 22 18 18 34 34 32 32 30 30 14 13 27 27 55 55 58 42 54 54 59 42 2 42 60 59 37 59 31 59 5 60 6 37 35 5 44 59 8 35 41 54 28 37 56 56 23 60 48 35 25 42 7 25 38 37 19 59 47 37 15 25 3 28 29 7 45 6 17 6 33 48 9 41 51 47 16 33 40 19 21 35 53 56 36 44 4 4 10 56 43 25 26 41 50 29 13 ...
output:
796836130
result:
ok single line: '796836130'
Subtask #4:
score: 10
Accepted
Test #20:
score: 10
Accepted
time: 3ms
memory: 3668kb
input:
10 6 2 8 3 5 3 1 8 9 1 2 8 10 3 4 1 7 9 6 7 7 5 5 9 7 8 6 4 3 6 5 7
output:
320
result:
ok single line: '320'
Test #21:
score: 0
Accepted
time: 3ms
memory: 3796kb
input:
11 7 2 7 6 11 7 9 7 5 9 2 6 1 5 8 1 10 9 3 8 4 11 6 9 2 4 7 5 1 3 11 6 6 5 1 11
output:
64
result:
ok single line: '64'
Test #22:
score: 0
Accepted
time: 1ms
memory: 3724kb
input:
12 1 2 6 1 9 6 5 9 4 9 10 1 2 10 3 9 11 1 12 5 8 11 7 12 7 5
output:
1024
result:
ok single line: '1024'
Test #23:
score: 0
Accepted
time: 3ms
memory: 3668kb
input:
13 6 2 12 10 5 12 2 5 4 12 13 10 8 4 9 12 7 5 11 9 1 4 6 10 3 10 13 9 2 13 5 8 3 7 9 2 7 4
output:
1152
result:
ok single line: '1152'
Test #24:
score: 0
Accepted
time: 5ms
memory: 3676kb
input:
14 13 2 14 6 1 14 12 14 8 1 10 1 7 12 3 8 11 12 5 14 9 6 4 5 2 10 13 11 7 1 8 2 1 3 11 6 9 10 14 8 1 5 8 5 6 5 8 5 11 6 9 10 9 3
output:
160
result:
ok single line: '160'
Test #25:
score: 0
Accepted
time: 5ms
memory: 3720kb
input:
15 13 2 12 7 3 12 9 7 8 3 1 9 5 7 4 9 14 12 15 12 2 4 6 8 10 4 11 14 13 8 6 12 2 14 4 13 7 11 7 14 12 5 14 9 5 1 11 13 11 9 2 5 8 14 14 8
output:
1696
result:
ok single line: '1696'
Test #26:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
15 7 2 9 8 4 8 14 5 5 8 15 13 13 5 2 3 3 13 11 7 7 3 1 6 6 7 12 10 10 6 9 4 14 4 15 4 2 4 11 4 1 4 12 4
output:
5462
result:
ok single line: '5462'
Subtask #5:
score: 65
Accepted
Test #27:
score: 65
Accepted
time: 7ms
memory: 3708kb
input:
52 14 997450415 17 30 7 17 25 7 16 30 14 30 42 14 10 17 51 42 33 51 18 7 12 30 20 30 32 20 9 17 24 32 8 51 36 8 46 42 26 10 13 42 11 18 4 17 40 17 47 33 34 9 21 4 48 7 45 33 2 13 29 11 41 10 38 16 1 34 5 33 37 1 50 36 52 11 27 16 3 46 44 2 15 51 43 20 23 12 49 4 22 10 6 20 31 16 28 40 19 20 35 20 39...
output:
967163788
result:
ok single line: '967163788'
Test #28:
score: 0
Accepted
time: 3ms
memory: 3756kb
input:
53 6 959296912 26 1 25 26 34 26 48 1 14 34 37 48 33 1 36 1 5 37 24 25 11 25 22 26 17 22 41 25 40 25 23 41 32 23 3 25 13 11 47 34 2 33 29 1 8 22 9 26 52 33 39 47 15 36 44 15 38 11 6 9 51 9 42 1 16 24 18 42 4 9 45 39 43 14 31 11 28 6 50 29 49 41 7 15 35 36 46 51 10 49 53 32 27 16 19 43 20 34 12 25 21 ...
output:
741042520
result:
ok single line: '741042520'
Test #29:
score: 0
Accepted
time: 1ms
memory: 3744kb
input:
54 2 72756471 3 21 41 21 37 21 25 3 30 25 45 21 14 25 46 30 5 41 28 5 17 14 31 46 39 3 43 21 11 31 15 28 38 15 51 39 35 41 10 11 20 10 40 37 32 39 26 39 12 46 22 26 27 28 48 27 49 17 16 26 29 21 1 32 34 39 53 26 8 27 54 15 24 48 23 40 47 21 36 3 50 3 52 32 44 54 2 15 9 29 42 52 18 42 6 25 7 22 33 28...
output:
604020626
result:
ok single line: '604020626'
Test #30:
score: 0
Accepted
time: 6ms
memory: 3792kb
input:
55 14 918922675 36 3 19 3 35 19 37 3 43 36 51 19 41 43 32 37 47 41 34 32 21 41 26 47 27 43 5 36 49 3 29 5 40 29 50 32 12 34 7 32 15 41 44 19 8 7 11 8 42 43 39 7 30 41 25 44 16 21 24 49 18 5 52 34 1 12 4 11 14 1 10 43 55 35 22 41 28 18 13 40 46 18 54 49 17 4 20 44 23 28 53 3 6 49 38 24 31 53 45 26 9 ...
output:
824664961
result:
ok single line: '824664961'
Test #31:
score: 0
Accepted
time: 4ms
memory: 3792kb
input:
56 12 162721445 27 53 33 27 45 33 39 33 7 53 50 53 11 45 55 50 12 7 5 55 42 7 54 12 52 39 31 39 25 11 6 39 14 45 34 53 35 42 41 55 24 5 3 31 20 5 44 5 2 11 47 44 48 11 56 3 32 55 51 6 30 2 23 53 37 35 18 42 36 25 1 11 10 56 49 47 28 6 15 31 46 41 9 36 4 23 16 28 26 37 13 34 8 44 29 28 40 45 22 18 21...
output:
813824978
result:
ok single line: '813824978'
Test #32:
score: 0
Accepted
time: 1ms
memory: 3676kb
input:
57 11 986819270 39 4 12 39 51 4 9 51 1 9 37 1 48 1 57 39 29 9 46 37 35 1 41 51 18 48 32 48 3 1 38 1 53 1 42 46 54 35 5 42 28 5 36 51 7 39 49 9 44 18 43 9 47 5 55 43 33 5 8 48 27 29 11 32 25 12 52 39 16 54 31 57 56 55 6 53 45 8 10 28 24 4 2 44 17 5 22 35 30 10 23 44 14 28 13 35 15 52 19 43 26 3 21 49...
output:
388122327
result:
ok single line: '388122327'
Test #33:
score: 0
Accepted
time: 3ms
memory: 3724kb
input:
58 8 119216380 10 31 44 10 29 31 56 44 13 56 47 56 2 56 57 44 32 13 12 57 30 44 42 13 50 2 20 13 26 13 6 47 17 29 54 20 40 26 43 44 41 30 51 43 49 32 3 40 14 43 39 2 9 26 16 10 37 29 11 40 21 37 18 26 45 57 7 11 34 47 19 7 35 13 46 49 38 10 27 14 55 46 22 12 48 38 52 18 1 38 8 49 53 16 4 20 5 55 24 ...
output:
879652313
result:
ok single line: '879652313'
Test #34:
score: 0
Accepted
time: 3ms
memory: 3732kb
input:
59 11 644458989 50 5 7 50 46 50 25 50 41 50 32 46 48 5 23 7 52 5 39 46 2 7 26 41 43 48 57 41 34 25 31 48 58 25 40 46 4 25 6 23 55 25 53 5 56 34 15 26 51 34 24 55 42 43 19 4 59 43 38 46 33 46 21 40 18 57 28 50 30 52 27 53 12 28 11 53 54 18 13 5 1 4 47 30 17 55 22 40 3 38 44 59 45 52 14 55 37 21 36 6 ...
output:
110322848
result:
ok single line: '110322848'
Test #35:
score: 0
Accepted
time: 6ms
memory: 3668kb
input:
60 13 493378949 9 1 44 1 47 9 35 47 58 9 19 58 39 1 12 39 57 47 15 12 48 9 6 57 30 12 14 47 32 47 7 44 2 58 4 39 23 35 41 15 25 6 24 41 46 58 38 12 5 57 16 6 50 57 13 35 53 39 3 58 17 12 11 53 20 23 10 25 43 53 18 30 27 7 60 39 37 24 8 7 22 41 51 44 56 9 33 46 26 5 31 33 42 39 49 7 54 53 34 23 59 46...
output:
129747968
result:
ok single line: '129747968'
Test #36:
score: 0
Accepted
time: 11ms
memory: 3792kb
input:
31 15 8345 24 8 16 8 28 10 10 8 18 13 13 10 27 15 15 13 31 22 22 15 14 4 4 22 23 11 11 4 21 20 20 11 3 30 30 20 19 6 6 30 1 7 7 6 9 2 2 7 12 25 25 2 5 29 29 25 26 17 17 29 24 16 28 16 18 16 27 16 31 16 14 16 23 16 21 16 3 16 19 16 1 16 9 16 12 16 5 16 26 16
output:
648137273
result:
ok single line: '648137273'
Test #37:
score: 0
Accepted
time: 11ms
memory: 3632kb
input:
29 14 8354645 7 21 18 21 29 2 2 21 20 12 12 2 28 26 26 12 10 3 3 26 16 22 22 3 6 19 19 22 17 1 1 19 13 27 27 1 4 11 11 27 14 24 24 11 8 23 23 24 25 9 9 23 5 15 15 9 7 18 29 18 20 18 28 18 10 18 16 18 6 18 17 18 13 18 4 18 14 18 8 18 25 18 5 18
output:
370336171
result:
ok single line: '370336171'
Extra Test:
score: 0
Extra Test Passed