106372024-04-07 15:08:11111Varázserdőcpp17Wrong answer 0/100762ms99576 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){
			sort(s.begin(),s.end());
			s.erase(unique(s.begin(),s.end()),s.end());
			for(int i:s){
				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
1Accepted3ms2100 KiB
2Accepted3ms2140 KiB
3Wrong answer2ms2228 KiB
subtask20/7
4Wrong answer3ms2428 KiB
5Wrong answer3ms2448 KiB
6Wrong answer7ms3348 KiB
7Wrong answer7ms3428 KiB
8Wrong answer294ms41708 KiB
9Wrong answer301ms42008 KiB
10Wrong answer289ms41992 KiB
11Wrong answer282ms42236 KiB
12Wrong answer277ms42452 KiB
13Wrong answer277ms42380 KiB
subtask30/9
14Wrong answer3ms3624 KiB
15Wrong answer3ms3760 KiB
16Wrong answer68ms13616 KiB
17Wrong answer349ms38700 KiB
18Wrong answer762ms82844 KiB
19Wrong answer675ms82840 KiB
20Wrong answer662ms82836 KiB
subtask40/14
21Wrong answer3ms3704 KiB
22Wrong answer3ms3704 KiB
23Wrong answer3ms3704 KiB
24Wrong answer3ms3708 KiB
subtask50/20
25Wrong answer3ms3848 KiB
26Wrong answer4ms3976 KiB
27Wrong answer4ms3996 KiB
28Wrong answer4ms3972 KiB
29Wrong answer4ms3976 KiB
30Wrong answer4ms3976 KiB
31Wrong answer4ms3988 KiB
32Wrong answer4ms4244 KiB
subtask60/50
33Wrong answer8ms4716 KiB
34Wrong answer67ms11892 KiB
35Accepted648ms55304 KiB
36Accepted660ms53316 KiB
37Wrong answer674ms68848 KiB
38Wrong answer660ms68064 KiB
39Wrong answer654ms83344 KiB
40Wrong answer683ms99576 KiB
41Wrong answer703ms62576 KiB