ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213642 | #573. t2 | wanghanyu393 | 0 | 0ms | 3740kb | C++ | 1.0kb | 2024-11-12 22:28:42 | 2024-11-13 00:03:17 |
answer
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int N = 1e5 + 5;
int ans[N];
vector<pair<int, int> >G[N];
void dfs(int u, int fa, int d){
ans[d]++;
for(int i = 0; i < G[u].size(); i++){
pair<int, int>pii = G[u][i];
int v = pii.first, w = pii.second;
if(v == fa) continue;
dfs(v, u, __gcd(d, w));
}
}
void solve(){
int n, q;
cin >> n >> q;
for(int i = 1; i < n; i++){
int u, v, w;
cin >> u >> v >> w;
G[u].push_back({v, w});
G[v].push_back({u, w});
}
for(int i = 1; i <= n; i++) dfs(i, 0, 0);
for(int i = 1; i <= n; i++){
for(int j = i * 2; j <= n; j += i){
ans[i] += ans[j];
}
}
for(int i = 1; i <= q; i++){
int d;
cin >> d;
cout << ans[d] / 2 << '\n';
}
}
int main(){
int t = 1;
//cin >> t;
while(t--){
solve();
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3740kb
input:
50 50 48 29 49788 47 48 31142 35 48 28665 10 35 23889 39 35 6411 50 39 66666 43 35 27629 46 10 49173...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
wrong answer 1st words differ - expected: '2', found: '0'
Subtask #2:
score: 0
Time Limit Exceeded
Test #11:
score: 0
Time Limit Exceeded
input:
100000 100000 73595 40695 76 13615 40695 96 65545 13615 84 19391 13615 76 2353 73595 27 26730 40695 ...
output:
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #21:
score: 0
Time Limit Exceeded
input:
100000 100000 73595 40695 12816 13615 73595 81821 65545 40695 75866 19391 65545 1165 2353 73595 3737...