9194 | 2024-02-17 21:59:27 | CWM | Testvérvárosok | cpp17 | Wrong answer 35/100 | 59ms | 20648 KiB |
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int main()
{
int n, k;
cin >> n >> k;
vector<vector<pair<int,int>>> g(n);
vector<int> modDist(n);
vector<bool> visited(n);
for (size_t i = 0; i < n-1; i++)
{
int a, b, w;
cin >> a >> b >> w;
a--; b--;
g[a].push_back({ b,w });
g[b].push_back({ a,w });
}
visited[0] = true;
queue<int> BFS;
BFS.push(0);
while (!BFS.empty())
{
int node = BFS.front();
BFS.pop();
for (size_t i = 0; i < g[node].size(); i++)
{
if (!visited[g[node][i].first]) {
visited[g[node][i].first] = true;
modDist[g[node][i].first] = (modDist[node] + g[node][i].second)%k;
BFS.push(g[node][i].first);
}
}
}
vector<int> kBuckets(k);
for (size_t i = 0; i < n; i++)
{
kBuckets[modDist[i]]++;
}
long long res = 0;
for (size_t i = 0; i < kBuckets.size(); i++)
{
int cnt = kBuckets[i];
res += (cnt * (cnt - 1) / 2);
}
cout << res;
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1812 KiB | ||||
2 | Wrong answer | 3ms | 2068 KiB | ||||
subtask2 | 0/15 | ||||||
3 | Wrong answer | 3ms | 2276 KiB | ||||
4 | Accepted | 3ms | 2360 KiB | ||||
5 | Wrong answer | 3ms | 2784 KiB | ||||
6 | Wrong answer | 3ms | 3108 KiB | ||||
7 | Accepted | 3ms | 3324 KiB | ||||
8 | Wrong answer | 3ms | 3352 KiB | ||||
9 | Wrong answer | 4ms | 3700 KiB | ||||
subtask3 | 15/15 | ||||||
10 | Accepted | 16ms | 5020 KiB | ||||
11 | Accepted | 4ms | 4148 KiB | ||||
12 | Accepted | 57ms | 10864 KiB | ||||
13 | Accepted | 52ms | 10880 KiB | ||||
14 | Accepted | 59ms | 12488 KiB | ||||
subtask4 | 20/20 | ||||||
15 | Accepted | 3ms | 6212 KiB | ||||
16 | Accepted | 3ms | 6252 KiB | ||||
17 | Accepted | 8ms | 7164 KiB | ||||
18 | Accepted | 26ms | 9292 KiB | ||||
19 | Accepted | 35ms | 10848 KiB | ||||
20 | Accepted | 48ms | 13020 KiB | ||||
21 | Accepted | 45ms | 13244 KiB | ||||
22 | Accepted | 54ms | 15116 KiB | ||||
subtask5 | 0/50 | ||||||
23 | Wrong answer | 52ms | 15716 KiB | ||||
24 | Wrong answer | 30ms | 13560 KiB | ||||
25 | Wrong answer | 39ms | 15100 KiB | ||||
26 | Wrong answer | 12ms | 12736 KiB | ||||
27 | Wrong answer | 28ms | 14544 KiB | ||||
28 | Wrong answer | 57ms | 18320 KiB | ||||
29 | Wrong answer | 54ms | 18548 KiB | ||||
30 | Accepted | 54ms | 19236 KiB | ||||
31 | Wrong answer | 59ms | 20648 KiB |