10200 | 2024-03-29 13:21:24 | 111 | Testvérvárosok | cpp17 | Wrong answer 0/100 | 1.6s | 47908 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,K;
cin>>N>>K;
vector<vector<pair<int,int>>>g(N+1);
for(int i=0;i<N-1;i++){
int a,b,d;
cin>>a>>b>>d;
g[a].emplace_back(b,d);
g[b].emplace_back(a,d);
}
int ans=0;
auto dfs=[&](auto self,int i,int p,int x)->multiset<int>{
multiset<int>s;
for(auto[j,d]:g[i]){
if(j==p){
continue;
}
auto z=self(self,j,i,x+d);
ans+=z.count((K-x%K)%K);
if(z.size()>s.size()){
swap(s,z);
}
for(int y:z){
ans+=s.count((K-(y-x)%K)%K);
}
s.insert(z.begin(),z.end());
}
s.insert(x%K);
return s;
};
dfs(dfs,1,0,0);
cout<<ans<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1824 KiB | ||||
2 | Accepted | 3ms | 2072 KiB | ||||
subtask2 | 0/15 | ||||||
3 | Wrong answer | 3ms | 2284 KiB | ||||
4 | Accepted | 3ms | 2492 KiB | ||||
5 | Wrong answer | 4ms | 3080 KiB | ||||
6 | Accepted | 3ms | 3104 KiB | ||||
7 | Accepted | 4ms | 3260 KiB | ||||
8 | Accepted | 3ms | 3304 KiB | ||||
9 | Wrong answer | 4ms | 3820 KiB | ||||
subtask3 | 0/15 | ||||||
10 | Wrong answer | 361ms | 7012 KiB | ||||
11 | Accepted | 24ms | 6160 KiB | ||||
12 | Time limit exceeded | 1.6s | 9712 KiB | ||||
13 | Time limit exceeded | 1.559s | 9404 KiB | ||||
14 | Time limit exceeded | 1.574s | 10620 KiB | ||||
subtask4 | 0/20 | ||||||
15 | Wrong answer | 3ms | 6252 KiB | ||||
16 | Wrong answer | 4ms | 6764 KiB | ||||
17 | Wrong answer | 9ms | 10844 KiB | ||||
18 | Wrong answer | 39ms | 23972 KiB | ||||
19 | Wrong answer | 86ms | 31924 KiB | ||||
20 | Wrong answer | 226ms | 42112 KiB | ||||
21 | Time limit exceeded | 1.582s | 22884 KiB | ||||
22 | Wrong answer | 101ms | 47908 KiB | ||||
subtask5 | 0/50 | ||||||
23 | Wrong answer | 98ms | 22152 KiB | ||||
24 | Wrong answer | 50ms | 17372 KiB | ||||
25 | Wrong answer | 68ms | 20556 KiB | ||||
26 | Wrong answer | 23ms | 13960 KiB | ||||
27 | Wrong answer | 50ms | 18564 KiB | ||||
28 | Wrong answer | 133ms | 25632 KiB | ||||
29 | Wrong answer | 101ms | 25572 KiB | ||||
30 | Time limit exceeded | 1.547s | 19008 KiB | ||||
31 | Wrong answer | 108ms | 28688 KiB |