10632 | 2024-04-07 14:26:58 | 111 | Varázserdő | cpp17 | Runtime error 7/100 | 2.164s | 478788 KiB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M;
cin>>N>>M;
vector<vector<pair<int,int>>>g(N+1);
vector<tuple<int,int,int>>e(M);
for(int i=0;i<M;i++){
int a,b,c;
cin>>a>>b>>c;
e[i]={c,a,b};
}
sort(e.rbegin(),e.rend());
for(int i=0;i<M;i++){
auto[c,a,b]=e[i];
g[a].emplace_back(b,c);
g[b].emplace_back(a,c);
}
vector<int>v(N+1);
vector<unordered_map<int,int>>w(N+1);
auto dfs=[&](auto self,int i)->void{
for(auto[j,c]:g[i]){
if(v[j]){
continue;
}
v[j]=v[i]+1;
self(self,j);
w[i][c]+=w[j][c+1]+1;
w[i][c]%=MOD;
}
};
v[1]=1;
dfs(dfs,1);
if(count(v.begin(),v.end(),0)!=1)exit(1);
auto dfs2=[&](auto self,int i)->void{
for(auto[j,c]:g[i]){
if(v[j]){
w[i][c]+=w[j][c+1]+1;
w[i][c]%=MOD;
continue;
}
v[j]=v[i]+1;
self(self,j);
}
};
fill(v.begin(),v.end(),0);
v[1]=1;
dfs2(dfs2,1);
int ans=0;
for(int i=1;i<=N;i++){
for(auto[x,y]:w[i]){
ans+=y;
ans%=MOD;
}
}
ans-=M;
cout<<ans<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1888 KiB | ||||
2 | Accepted | 3ms | 2020 KiB | ||||
3 | Accepted | 3ms | 2104 KiB | ||||
subtask2 | 7/7 | ||||||
4 | Accepted | 3ms | 2408 KiB | ||||
5 | Accepted | 4ms | 3400 KiB | ||||
6 | Accepted | 17ms | 11652 KiB | ||||
7 | Accepted | 17ms | 12092 KiB | ||||
8 | Accepted | 1.259s | 470484 KiB | ||||
9 | Accepted | 1.202s | 468952 KiB | ||||
10 | Accepted | 1.111s | 467592 KiB | ||||
11 | Accepted | 1.024s | 469176 KiB | ||||
12 | Accepted | 972ms | 474656 KiB | ||||
13 | Accepted | 968ms | 477816 KiB | ||||
subtask3 | 0/9 | ||||||
14 | Runtime error | 3ms | 49224 KiB | ||||
15 | Runtime error | 4ms | 50104 KiB | ||||
16 | Runtime error | 75ms | 83076 KiB | ||||
17 | Runtime error | 479ms | 189600 KiB | ||||
18 | Runtime error | 1.547s | 478788 KiB | ||||
19 | Runtime error | 1.041s | 401832 KiB | ||||
20 | Runtime error | 1.027s | 420396 KiB | ||||
subtask4 | 0/14 | ||||||
21 | Wrong answer | 3ms | 70356 KiB | ||||
22 | Wrong answer | 3ms | 70364 KiB | ||||
23 | Wrong answer | 3ms | 70344 KiB | ||||
24 | Runtime error | 3ms | 70348 KiB | ||||
subtask5 | 0/20 | ||||||
25 | Runtime error | 4ms | 71028 KiB | ||||
26 | Wrong answer | 8ms | 72848 KiB | ||||
27 | Wrong answer | 8ms | 72220 KiB | ||||
28 | Wrong answer | 8ms | 73004 KiB | ||||
29 | Runtime error | 6ms | 72156 KiB | ||||
30 | Runtime error | 6ms | 72140 KiB | ||||
31 | Wrong answer | 8ms | 72728 KiB | ||||
32 | Wrong answer | 8ms | 72732 KiB | ||||
subtask6 | 0/50 | ||||||
33 | Runtime error | 13ms | 77444 KiB | ||||
34 | Runtime error | 78ms | 104868 KiB | ||||
35 | Wrong answer | 878ms | 223436 KiB | ||||
36 | Wrong answer | 930ms | 267960 KiB | ||||
37 | Runtime error | 1.098s | 436748 KiB | ||||
38 | Runtime error | 1.103s | 437572 KiB | ||||
39 | Runtime error | 1.09s | 439916 KiB | ||||
40 | Runtime error | 1.092s | 443324 KiB | ||||
41 | Wrong answer | 2.164s | 322888 KiB |