QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#188925#7509. 01treezhoukangyang#WA 4ms32332kbC++112.1kb2023-09-26 16:52:132023-09-26 16:52:14

Judging History

你现在查看的是最新测评结果

  • [2023-09-26 16:52:14]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:32332kb
  • [2023-09-26 16:52:13]
  • 提交

answer

#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long 
#define vi vector < int > 
#define sz(a) ((int) (a).size())
#define ll long long 
#define ull unsigned long long
#define me(a, x) memset(a, x, sizeof(a)) 
using namespace std;
const int N = 1 << 19, mod = 1e9 + 7;

int qpow(int x, int y = mod - 2) {
	int res = 1;
	for(; y; x = (ll) x * x % mod, y >>= 1) if(y & 1) res = (ll) res * x % mod;
	return res;
}
int fac[N], ifac[N], inv[N];
void init(int x) {
	fac[0] = ifac[0] = inv[1] = 1;
	L(i, 2, x) inv[i] = (ll) (mod - mod / i) * inv[mod % i] % mod;
	L(i, 1, x) fac[i] = (ll) fac[i - 1] * i % mod, ifac[i] = (ll) ifac[i - 1] * inv[i] % mod;
} 
int C(int x, int y) {
	return x < y || y < 0 ? 0 : (ll) fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}

int n;
char s[N], t[N];
vi e[N];

int scnt[N], snon[N];
int tcnt[N], tnon[N];
int col[N];
void dfs(int x, int fa) {
	if(col[x]) {
		if(s[x] != '?') 
			s[x] ^= 1;
		if(t[x] != '?') 
			t[x] ^= 1;
	} 
	scnt[x] = s[x] == '1';
	snon[x] = s[x] == '?';
	
	tcnt[x] = t[x] == '1';
	tnon[x] = t[x] == '?';
	for(auto v : e[x]) if(v != fa) {
		col[v] = col[x] ^ 1, dfs(v, x);
		scnt[x] += scnt[v];
		snon[x] += snon[v];
		
		tcnt[x] += tcnt[v];
		tnon[x] += tnon[v];
	}
}

void Main() {
	cin >> n;
	L(i, 1, n - 1) {
		int u, v;
		cin >> u >> v;
		e[u].emplace_back(v);
		e[v].emplace_back(u);
	}
	cin >> (s + 1) >> (t + 1);
	col[1] = 0, dfs(1, 0);
	
	int ans = 0;
	int qwq = tnon[1] + tcnt[1] - scnt[1];
	L(i, 2, n) {
		int xs = snon[1] - snon[i];
		int ys = snon[i];
		
		int xt = tnon[1] - tnon[i];
		int yt = tnon[i];
		
		int L = xs + xt;
		int R = ys + yt;
		int D = qwq - (yt - scnt[i] - tcnt[i]);
		
		L(a, 0, L) 
			(ans += (ll) C(L, a) * C(R, qwq - a) % mod * abs(D - a) % mod) %= mod;
	}
	cout << ans << '\n';
	
	L(i, 1, n) {
		e[i].clear();
	}
}

int main() {
	init(2e5 + 7);
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t; cin >> t; while(t--) Main();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 32332kb

input:

3
2
1 2
00
11
3
1 2
2 3
???
???
3
1 2
2 3
??1
0?0

output:

1
16
1

result:

ok 3 number(s): "1 16 1"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 30360kb

input:

1000
23
1 2
1 3
1 4
2 5
5 6
4 7
3 8
4 9
8 10
8 11
8 12
1 13
7 14
10 15
7 16
7 17
5 18
18 19
12 20
9 21
21 22
6 23
00?10?0000??1?00111?010
011??1?10?01?110?0??101
6
1 2
1 3
1 4
4 5
3 6
000?10
1???01
25
1 2
2 3
2 4
4 5
5 6
2 7
4 8
5 9
7 10
8 11
11 12
5 13
11 14
3 15
6 16
14 17
1 18
4 19
6 20
4 21
5 22...

output:

121011
30
46580
3788
294
34
3177
76
998
8764
52
2
15
1744
26090
7798
1753050
0
269126
3
266
179025
62788
18
173173
23976
5565936
68064736
2018
3
657514
4384
734552
17038
744
320
15
5369078
95196
51300
23
0
2
24318
4255848
285029
371393
582439
81294
136
2312
2891476
88560
4459780
5255822
2095936
4628...

result:

wrong answer 1st numbers differ - expected: '53545', found: '121011'