传送门https://ac.nowcoder.com/acm/contest/1099/I
本来这题应该是考的树形dp(但是dp永远的痛)就尝试用点分治写一下,改了好久才改出来
本题求的是树上两点之间的权值和是2019的倍数的路径有多少,那个u<v的条件其实就是让你一条路径只算一次,反着不算一条新的。这里最主要的代码就是下面
for(int j = 0; j < cnt; j ++){
int t = temp[j];
if(temp[j] > mod)
t = t % mod;
if(t == 0 || t == mod){
ans ++;
ans += judge[0];
ans += judge[mod];
//cout << ans << endl;
}
else if(judge[mod - t]){
ans += judge[mod - t];
}
}
for(int j = 0; j < cnt; j ++){
if(temp[j] > 2019)
temp[j] %= 2019;
que.push(temp[j]);
judge[temp[j]] ++;
}

最低0.47元/天 解锁文章
3615

被折叠的 条评论
为什么被折叠?



