10201 | 2024-03-29 13:27:52 | 111 | Testvérvárosok | cpp17 | Wrong answer 0/100 | 1.575s | 41996 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%K+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 | 1696 KiB | ||||
2 | Accepted | 3ms | 1880 KiB | ||||
subtask2 | 0/15 | ||||||
3 | Wrong answer | 3ms | 2088 KiB | ||||
4 | Accepted | 3ms | 2156 KiB | ||||
5 | Wrong answer | 4ms | 2528 KiB | ||||
6 | Accepted | 4ms | 2848 KiB | ||||
7 | Accepted | 4ms | 3032 KiB | ||||
8 | Accepted | 3ms | 2784 KiB | ||||
9 | Wrong answer | 4ms | 2988 KiB | ||||
subtask3 | 0/15 | ||||||
10 | Wrong answer | 363ms | 6248 KiB | ||||
11 | Accepted | 24ms | 5284 KiB | ||||
12 | Time limit exceeded | 1.575s | 8404 KiB | ||||
13 | Time limit exceeded | 1.559s | 7400 KiB | ||||
14 | Time limit exceeded | 1.567s | 7716 KiB | ||||
subtask4 | 0/20 | ||||||
15 | Wrong answer | 3ms | 3528 KiB | ||||
16 | Wrong answer | 3ms | 4100 KiB | ||||
17 | Wrong answer | 9ms | 7848 KiB | ||||
18 | Wrong answer | 39ms | 20668 KiB | ||||
19 | Wrong answer | 87ms | 27940 KiB | ||||
20 | Wrong answer | 230ms | 37496 KiB | ||||
21 | Time limit exceeded | 1.536s | 17708 KiB | ||||
22 | Wrong answer | 103ms | 41996 KiB | ||||
subtask5 | 0/50 | ||||||
23 | Wrong answer | 101ms | 15720 KiB | ||||
24 | Wrong answer | 50ms | 10268 KiB | ||||
25 | Wrong answer | 70ms | 13084 KiB | ||||
26 | Wrong answer | 23ms | 6632 KiB | ||||
27 | Wrong answer | 52ms | 10720 KiB | ||||
28 | Wrong answer | 136ms | 17168 KiB | ||||
29 | Wrong answer | 98ms | 16132 KiB | ||||
30 | Time limit exceeded | 1.567s | 8792 KiB | ||||
31 | Wrong answer | 115ms | 17688 KiB |