This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define F first
#define S second
#define int long long
#define pb push_back
using namespace std;
const int N=2e5+10,M=2e3,mod=1e9+7;
int cost[N],seg[N*4],ans[N];
vector<pair<int,int>>adj[N];
map<pair<int,int>,int>mp;
void dfs(int node,int par){
for(auto x:adj[node]){
if(x.F==par)
continue;
ans[x.F]=ans[node]+cost[node]-mp[{node,x.F}];
if(ans[x.F]<0)
continue;
dfs(x.F,node);
}
}
main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>cost[i];
for(int i=0;i<n-1;i++){
int x,y,z;
cin>>x>>y>>z;
adj[x].pb({y,z});
adj[y].pb({x,z});
mp[{x,y}]=z;
mp[{y,x}]=z;
}
int anss=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)
ans[j]=-1e18;
ans[i]=0;
dfs(i,0);
for(int j=1;j<=n;j++)
if(ans[j]!=1e18&&ans[j]>=0&&i!=j)
anss++;
}
cout<<anss<<endl;
return 0;
}
Compilation message (stderr)
transport.cpp:29:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
29 | main()
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |