106392024-04-07 15:15:22111Varázserdőcpp17Accepted 100/100584ms35600 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),l(N+1);
	for(int i=0;i<M;i++){
		auto[c,a,b]=e[i];
		if(l[a]!=c){
			ans+=w[a];
			v[a]=l[a]+1==c?w[a]:0;
			w[a]=0;
			l[a]=c;
		}
		if(l[b]!=c){
			ans+=w[b];
			v[b]=l[b]+1==c?w[b]:0;
			w[b]=0;
			l[b]=c;
		}
		w[a]+=v[b]+1;
		w[a]%=MOD;
		w[b]+=v[a]+1;
		w[b]%=MOD;
	}
	for(int i=1;i<=N;i++){
		ans+=w[i];
	}
	ans+=MOD-M;
	ans%=MOD;
	cout<<ans<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted2ms228 KiB
2Accepted3ms484 KiB
3Accepted3ms356 KiB
subtask27/7
4Accepted3ms528 KiB
5Accepted3ms484 KiB
6Accepted7ms868 KiB
7Accepted7ms892 KiB
8Accepted300ms23800 KiB
9Accepted279ms23800 KiB
10Accepted289ms23908 KiB
11Accepted275ms23780 KiB
12Accepted268ms23908 KiB
13Accepted261ms23844 KiB
subtask39/9
14Accepted3ms632 KiB
15Accepted3ms632 KiB
16Accepted52ms5168 KiB
17Accepted256ms14504 KiB
18Accepted584ms35600 KiB
19Accepted541ms35484 KiB
20Accepted514ms35504 KiB
subtask414/14
21Accepted3ms360 KiB
22Accepted3ms356 KiB
23Accepted2ms356 KiB
24Accepted3ms392 KiB
subtask520/20
25Accepted3ms356 KiB
26Accepted4ms612 KiB
27Accepted4ms484 KiB
28Accepted4ms660 KiB
29Accepted4ms372 KiB
30Accepted4ms500 KiB
31Accepted4ms500 KiB
32Accepted4ms744 KiB
subtask650/50
33Accepted7ms868 KiB
34Accepted54ms5124 KiB
35Accepted504ms24092 KiB
36Accepted514ms23980 KiB
37Accepted537ms35444 KiB
38Accepted550ms35556 KiB
39Accepted568ms35588 KiB
40Accepted561ms35556 KiB
41Accepted519ms26268 KiB