106382024-04-07 15:10:22111Varázserdőcpp17Wrong answer 0/100577ms99384 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1824 KiB
2Accepted3ms2056 KiB
3Wrong answer3ms2272 KiB
subtask20/7
4Wrong answer3ms2460 KiB
5Wrong answer3ms2856 KiB
6Wrong answer7ms3852 KiB
7Wrong answer7ms3828 KiB
8Wrong answer270ms41792 KiB
9Wrong answer270ms41964 KiB
10Wrong answer264ms41964 KiB
11Wrong answer257ms41860 KiB
12Wrong answer259ms41860 KiB
13Wrong answer252ms41856 KiB
subtask30/9
14Wrong answer3ms3112 KiB
15Wrong answer3ms3132 KiB
16Wrong answer52ms12876 KiB
17Wrong answer261ms37808 KiB
18Wrong answer572ms82128 KiB
19Wrong answer537ms82300 KiB
20Wrong answer532ms82428 KiB
subtask40/14
21Wrong answer3ms3256 KiB
22Wrong answer3ms3388 KiB
23Wrong answer3ms3492 KiB
24Wrong answer2ms3492 KiB
subtask50/20
25Wrong answer3ms3520 KiB
26Wrong answer4ms3744 KiB
27Wrong answer4ms3768 KiB
28Wrong answer4ms3948 KiB
29Wrong answer4ms3800 KiB
30Wrong answer4ms3812 KiB
31Wrong answer4ms3892 KiB
32Wrong answer4ms3816 KiB
subtask60/50
33Wrong answer7ms4160 KiB
34Wrong answer52ms11452 KiB
35Accepted507ms54860 KiB
36Accepted513ms52620 KiB
37Wrong answer556ms68272 KiB
38Wrong answer537ms67472 KiB
39Wrong answer577ms83160 KiB
40Wrong answer565ms99384 KiB
41Wrong answer529ms62400 KiB