Submission #598509

# Submission time Handle Problem Language Result Execution time Memory
598509 2022-07-18T12:34:46 Z AGE Transport (COCI19_transport) C++14
26 / 130
1000 ms 33616 KB
#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

transport.cpp:29:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   29 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 205 ms 5708 KB Output is correct
2 Correct 116 ms 5884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 483 ms 6476 KB Output is correct
2 Correct 38 ms 5972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1095 ms 20172 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 26144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1081 ms 33616 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1096 ms 10924 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1069 ms 14792 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 18252 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 22016 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1081 ms 27872 KB Time limit exceeded
2 Halted 0 ms 0 KB -