10636 | 2024-04-07 15:06:36 | 111 | Varázserdő | cpp17 | Time limit exceeded 50/100 | 5.076s | 113356 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);
for(int i=0;i<M;i++){
auto[c,a,b]=e[i];
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=1;i<=N;i++){
if(c+1==cc){
v[i]=w[i];
}
else{
v[i]=0;
}
ans+=w[i];
ans%=MOD;
w[i]=0;
}
}
}
ans+=MOD-M;
ans%=MOD;
cout<<ans<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
2 | Accepted | 3ms | 2020 KiB | ||||
3 | Accepted | 3ms | 2236 KiB | ||||
subtask2 | 7/7 | ||||||
4 | Accepted | 3ms | 2448 KiB | ||||
5 | Accepted | 3ms | 2572 KiB | ||||
6 | Accepted | 13ms | 3404 KiB | ||||
7 | Accepted | 13ms | 3520 KiB | ||||
8 | Accepted | 1.741s | 50216 KiB | ||||
9 | Accepted | 1.743s | 58780 KiB | ||||
10 | Accepted | 1.736s | 67324 KiB | ||||
11 | Accepted | 1.74s | 75792 KiB | ||||
12 | Accepted | 1.726s | 84468 KiB | ||||
13 | Accepted | 1.725s | 89264 KiB | ||||
subtask3 | 9/9 | ||||||
14 | Accepted | 3ms | 50600 KiB | ||||
15 | Accepted | 3ms | 50732 KiB | ||||
16 | Accepted | 52ms | 58196 KiB | ||||
17 | Accepted | 252ms | 77268 KiB | ||||
18 | Accepted | 544ms | 113320 KiB | ||||
19 | Accepted | 514ms | 113204 KiB | ||||
20 | Accepted | 510ms | 113356 KiB | ||||
subtask4 | 14/14 | ||||||
21 | Accepted | 3ms | 50812 KiB | ||||
22 | Accepted | 2ms | 50904 KiB | ||||
23 | Accepted | 2ms | 50804 KiB | ||||
24 | Accepted | 2ms | 50812 KiB | ||||
subtask5 | 20/20 | ||||||
25 | Accepted | 3ms | 50824 KiB | ||||
26 | Accepted | 4ms | 51040 KiB | ||||
27 | Accepted | 4ms | 51036 KiB | ||||
28 | Accepted | 4ms | 51044 KiB | ||||
29 | Accepted | 4ms | 51040 KiB | ||||
30 | Accepted | 4ms | 51036 KiB | ||||
31 | Accepted | 4ms | 51048 KiB | ||||
32 | Accepted | 4ms | 51048 KiB | ||||
subtask6 | 0/50 | ||||||
33 | Accepted | 8ms | 51536 KiB | ||||
34 | Accepted | 68ms | 58588 KiB | ||||
35 | Accepted | 497ms | 98008 KiB | ||||
36 | Accepted | 507ms | 98008 KiB | ||||
37 | Accepted | 578ms | 113260 KiB | ||||
38 | Accepted | 662ms | 113268 KiB | ||||
39 | Time limit exceeded | 5.065s | 81540 KiB | ||||
40 | Time limit exceeded | 5.076s | 81504 KiB | ||||
41 | Accepted | 517ms | 100940 KiB |