106342024-04-07 14:57:11111Varázserdőcpp17Wrong answer 14/1004ms3980 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[b]+=v[a]+1;
		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];
				w[i]=0;
			}
		}
	}
	ans-=M;
	cout<<ans<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2024 KiB
3Accepted3ms2252 KiB
subtask20/7
4Wrong answer3ms2472 KiB
5Accepted3ms2600 KiB
6Runtime error3ms2684 KiB
7Runtime error2ms2788 KiB
8Runtime error2ms2800 KiB
9Runtime error2ms2820 KiB
10Runtime error3ms2960 KiB
11Runtime error2ms3064 KiB
12Runtime error2ms3076 KiB
13Runtime error2ms3092 KiB
subtask30/9
14Accepted2ms3108 KiB
15Accepted3ms3248 KiB
16Runtime error2ms3300 KiB
17Runtime error2ms3312 KiB
18Runtime error3ms3348 KiB
19Runtime error2ms3432 KiB
20Runtime error2ms3432 KiB
subtask414/14
21Accepted2ms3516 KiB
22Accepted2ms3428 KiB
23Accepted3ms3572 KiB
24Accepted2ms3656 KiB
subtask50/20
25Accepted3ms3588 KiB
26Accepted4ms3884 KiB
27Accepted4ms3888 KiB
28Accepted4ms3884 KiB
29Accepted4ms3888 KiB
30Accepted4ms3880 KiB
31Wrong answer4ms3980 KiB
32Wrong answer4ms3980 KiB
subtask60/50
33Runtime error2ms3628 KiB
34Runtime error2ms3628 KiB
35Runtime error2ms3736 KiB
36Runtime error2ms3836 KiB
37Runtime error2ms3736 KiB
38Runtime error2ms3740 KiB
39Runtime error2ms3744 KiB
40Runtime error2ms3648 KiB
41Runtime error2ms3648 KiB