106362024-04-07 15:06:36111Varázserdőcpp17Time limit exceeded 50/1005.076s113356 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2020 KiB
3Accepted3ms2236 KiB
subtask27/7
4Accepted3ms2448 KiB
5Accepted3ms2572 KiB
6Accepted13ms3404 KiB
7Accepted13ms3520 KiB
8Accepted1.741s50216 KiB
9Accepted1.743s58780 KiB
10Accepted1.736s67324 KiB
11Accepted1.74s75792 KiB
12Accepted1.726s84468 KiB
13Accepted1.725s89264 KiB
subtask39/9
14Accepted3ms50600 KiB
15Accepted3ms50732 KiB
16Accepted52ms58196 KiB
17Accepted252ms77268 KiB
18Accepted544ms113320 KiB
19Accepted514ms113204 KiB
20Accepted510ms113356 KiB
subtask414/14
21Accepted3ms50812 KiB
22Accepted2ms50904 KiB
23Accepted2ms50804 KiB
24Accepted2ms50812 KiB
subtask520/20
25Accepted3ms50824 KiB
26Accepted4ms51040 KiB
27Accepted4ms51036 KiB
28Accepted4ms51044 KiB
29Accepted4ms51040 KiB
30Accepted4ms51036 KiB
31Accepted4ms51048 KiB
32Accepted4ms51048 KiB
subtask60/50
33Accepted8ms51536 KiB
34Accepted68ms58588 KiB
35Accepted497ms98008 KiB
36Accepted507ms98008 KiB
37Accepted578ms113260 KiB
38Accepted662ms113268 KiB
39Time limit exceeded5.065s81540 KiB
40Time limit exceeded5.076s81504 KiB
41Accepted517ms100940 KiB