106352024-04-07 14:58:13111Varázserdőcpp17Wrong answer 34/1004ms3780 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;
	if(N>1000||M>5000)exit(1);
	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?MOD:get<0>(e[i+1]);
		if(c!=cc){
			for(int i=1;i<=N;i++){
				if(c+1==cc){
					v[i]=w[i];
				}
				ans+=w[i];
				ans%=MOD;
				w[i]=0;
			}
		}
	}
	ans+=MOD-M;
	ans%=MOD;
	cout<<ans<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2100 KiB
2Accepted3ms2080 KiB
3Accepted3ms2320 KiB
subtask20/7
4Wrong answer3ms2380 KiB
5Accepted3ms2760 KiB
6Runtime error3ms2704 KiB
7Runtime error3ms2928 KiB
8Runtime error3ms3108 KiB
9Runtime error2ms3184 KiB
10Runtime error2ms3172 KiB
11Runtime error2ms3168 KiB
12Runtime error2ms3176 KiB
13Runtime error2ms3276 KiB
subtask30/9
14Accepted2ms3276 KiB
15Accepted3ms3316 KiB
16Runtime error2ms3324 KiB
17Runtime error2ms3224 KiB
18Runtime error2ms3240 KiB
19Runtime error3ms3412 KiB
20Runtime error2ms3372 KiB
subtask414/14
21Accepted2ms3476 KiB
22Accepted2ms3464 KiB
23Accepted2ms3468 KiB
24Accepted2ms3464 KiB
subtask520/20
25Accepted3ms3568 KiB
26Accepted4ms3632 KiB
27Accepted4ms3628 KiB
28Accepted4ms3728 KiB
29Accepted4ms3780 KiB
30Accepted4ms3736 KiB
31Accepted4ms3744 KiB
32Accepted4ms3752 KiB
subtask60/50
33Runtime error2ms3528 KiB
34Runtime error2ms3532 KiB
35Runtime error2ms3448 KiB
36Runtime error2ms3448 KiB
37Runtime error2ms3552 KiB
38Runtime error2ms3656 KiB
39Runtime error2ms3616 KiB
40Runtime error2ms3720 KiB
41Runtime error2ms3620 KiB