10633 | 2024-04-07 14:28:12 | 111 | Varázserdő | cpp17 | Wrong answer 7/100 | 3.836s | 504308 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;
}
};
for(int i=1;i<=N;i++){
if(v[i]){
continue;
}
v[i]=1;
dfs(dfs,i);
}
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);
for(int i=1;i<=N;i++){
if(v[i]){
continue;
}
v[i]=1;
dfs2(dfs2,i);
}
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 | 1892 KiB | ||||
2 | Accepted | 3ms | 2124 KiB | ||||
3 | Accepted | 3ms | 2348 KiB | ||||
subtask2 | 7/7 | ||||||
4 | Accepted | 3ms | 2724 KiB | ||||
5 | Accepted | 4ms | 3684 KiB | ||||
6 | Accepted | 16ms | 11792 KiB | ||||
7 | Accepted | 18ms | 12604 KiB | ||||
8 | Accepted | 1.253s | 470932 KiB | ||||
9 | Accepted | 981ms | 469776 KiB | ||||
10 | Accepted | 1.118s | 467956 KiB | ||||
11 | Accepted | 852ms | 469792 KiB | ||||
12 | Accepted | 967ms | 475088 KiB | ||||
13 | Accepted | 963ms | 477812 KiB | ||||
subtask3 | 0/9 | ||||||
14 | Wrong answer | 3ms | 49292 KiB | ||||
15 | Wrong answer | 4ms | 50200 KiB | ||||
16 | Wrong answer | 215ms | 120684 KiB | ||||
17 | Wrong answer | 1.062s | 202624 KiB | ||||
18 | Wrong answer | 3.836s | 504308 KiB | ||||
19 | Wrong answer | 2.032s | 402584 KiB | ||||
20 | Wrong answer | 2.118s | 411844 KiB | ||||
subtask4 | 0/14 | ||||||
21 | Wrong answer | 3ms | 22760 KiB | ||||
22 | Wrong answer | 3ms | 22996 KiB | ||||
23 | Wrong answer | 3ms | 23080 KiB | ||||
24 | Wrong answer | 3ms | 23068 KiB | ||||
subtask5 | 0/20 | ||||||
25 | Wrong answer | 4ms | 23924 KiB | ||||
26 | Wrong answer | 8ms | 25824 KiB | ||||
27 | Wrong answer | 8ms | 24968 KiB | ||||
28 | Wrong answer | 8ms | 25676 KiB | ||||
29 | Wrong answer | 8ms | 25532 KiB | ||||
30 | Wrong answer | 8ms | 25360 KiB | ||||
31 | Wrong answer | 8ms | 24796 KiB | ||||
32 | Wrong answer | 8ms | 24900 KiB | ||||
subtask6 | 0/50 | ||||||
33 | Wrong answer | 20ms | 30784 KiB | ||||
34 | Wrong answer | 321ms | 101104 KiB | ||||
35 | Wrong answer | 866ms | 162564 KiB | ||||
36 | Wrong answer | 913ms | 195188 KiB | ||||
37 | Wrong answer | 2.601s | 446864 KiB | ||||
38 | Wrong answer | 2.197s | 468404 KiB | ||||
39 | Wrong answer | 3.368s | 500580 KiB | ||||
40 | Wrong answer | 3.124s | 486872 KiB | ||||
41 | Wrong answer | 1.664s | 262572 KiB |