ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213590 | #573. t2 | LazyCat | 0 | 0ms | 0kb | C++ | 948b | 2024-11-12 21:23:50 | 2024-11-12 23:52:00 |
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
bool back=false;
int n,q,ans;
vector<pair<int,int> >e[maxn];
queue<pair<int,int> > p;
void dfs(int d){
while(!p.empty()){
pair<int,int> now=p.front();
p.pop();
bool end=true;
for(int i=0;i<sizeof(e[now.first]);i++){
if(!(e[now.first][i].second%d)){
if(back){
back=false;
ans-=now.second*(now.second-1);
}
end=false;
p.push(make_pair(e[now.first][i].first,now.second+1));
}
}
if(end){
back=true;
ans+=now.second*(now.second-1);
}
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> n >> q;
for(int i=1;i<=n;i++){
int u,v,w;
cin >> u >> v >> w;
e[u].push_back(make_pair(v,w));
e[v].push_back(make_pair(u,w));
}
int d;
ans=0;
while(q--){
cin >> d;
p.push(make_pair(1,0));
dfs(d);
cout<<ans<<endl;
back=false;
ans=0;
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
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:
result:
Subtask #2:
score: 0
Runtime Error
Test #11:
score: 0
Runtime Error
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
Runtime Error
Test #21:
score: 0
Runtime Error
input:
100000 100000 73595 40695 12816 13615 73595 81821 65545 40695 75866 19391 65545 1165 2353 73595 3737...