10638 | 2024-04-07 15:10:22 | 111 | Varázserdő | cpp17 | Wrong answer 0/100 | 577ms | 99384 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<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.begin(),e.end());
int ans=0;
vector<int>v(N+1),w(N+1),s;
for(int i=0;i<M;i++){
auto[c,a,b]=e[i];
s.push_back(a);
s.push_back(b);
w[a]+=v[b]+1;
w[a]%=MOD;
w[b]+=v[a]+1;
w[b]%=MOD;
int cc=i+1==M?c+2:get<0>(e[i+1]);
if(c!=cc){
for(int i:s){
if(w[i]==0){
continue;
}
if(c+1==cc){
v[i]=w[i];
}
else{
v[i]=0;
}
ans+=w[i];
ans%=MOD;
w[i]=0;
}
s.clear();
}
}
ans+=MOD-M;
ans%=MOD;
cout<<ans<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1824 KiB | ||||
2 | Accepted | 3ms | 2056 KiB | ||||
3 | Wrong answer | 3ms | 2272 KiB | ||||
subtask2 | 0/7 | ||||||
4 | Wrong answer | 3ms | 2460 KiB | ||||
5 | Wrong answer | 3ms | 2856 KiB | ||||
6 | Wrong answer | 7ms | 3852 KiB | ||||
7 | Wrong answer | 7ms | 3828 KiB | ||||
8 | Wrong answer | 270ms | 41792 KiB | ||||
9 | Wrong answer | 270ms | 41964 KiB | ||||
10 | Wrong answer | 264ms | 41964 KiB | ||||
11 | Wrong answer | 257ms | 41860 KiB | ||||
12 | Wrong answer | 259ms | 41860 KiB | ||||
13 | Wrong answer | 252ms | 41856 KiB | ||||
subtask3 | 0/9 | ||||||
14 | Wrong answer | 3ms | 3112 KiB | ||||
15 | Wrong answer | 3ms | 3132 KiB | ||||
16 | Wrong answer | 52ms | 12876 KiB | ||||
17 | Wrong answer | 261ms | 37808 KiB | ||||
18 | Wrong answer | 572ms | 82128 KiB | ||||
19 | Wrong answer | 537ms | 82300 KiB | ||||
20 | Wrong answer | 532ms | 82428 KiB | ||||
subtask4 | 0/14 | ||||||
21 | Wrong answer | 3ms | 3256 KiB | ||||
22 | Wrong answer | 3ms | 3388 KiB | ||||
23 | Wrong answer | 3ms | 3492 KiB | ||||
24 | Wrong answer | 2ms | 3492 KiB | ||||
subtask5 | 0/20 | ||||||
25 | Wrong answer | 3ms | 3520 KiB | ||||
26 | Wrong answer | 4ms | 3744 KiB | ||||
27 | Wrong answer | 4ms | 3768 KiB | ||||
28 | Wrong answer | 4ms | 3948 KiB | ||||
29 | Wrong answer | 4ms | 3800 KiB | ||||
30 | Wrong answer | 4ms | 3812 KiB | ||||
31 | Wrong answer | 4ms | 3892 KiB | ||||
32 | Wrong answer | 4ms | 3816 KiB | ||||
subtask6 | 0/50 | ||||||
33 | Wrong answer | 7ms | 4160 KiB | ||||
34 | Wrong answer | 52ms | 11452 KiB | ||||
35 | Accepted | 507ms | 54860 KiB | ||||
36 | Accepted | 513ms | 52620 KiB | ||||
37 | Wrong answer | 556ms | 68272 KiB | ||||
38 | Wrong answer | 537ms | 67472 KiB | ||||
39 | Wrong answer | 577ms | 83160 KiB | ||||
40 | Wrong answer | 565ms | 99384 KiB | ||||
41 | Wrong answer | 529ms | 62400 KiB |