# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
569830 | Lobo | Road Closures (APIO21_roads) | C++17 | 77 ms | 21140 KiB |
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 "roads.h"
#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 2e5+10;
int n;
vector<pair<int,int>> g[maxn];
int dp[maxn][2], mark[maxn][2];
//fl = 1 -> o anterior ta usado
int sol(int u, int fl) {
if(mark[u][fl]) return dp[u][fl];
dp[u][fl] = inf;
mark[u][fl] = 1;
if(u == n) {
return dp[u][fl] = 0;
}
int v = u+1;
int w;
for(auto V : g[u]) if(V.fr == v) {
w = V.sc;
}
if(fl) dp[u][fl] = min(dp[u][fl],sol(v,0));
dp[u][fl] = min(dp[u][fl], w+sol(v,1));
return dp[u][fl];
}
vector<int> minimum_closure_costs(int32_t N, vector<int32_t> U, vector<int32_t> V, vector<int32_t> W) {
n = N;
int sm = 0;
for(int i = 0; i < n-1; i++) {
g[U[i]+1].pb(mp(V[i]+1,W[i]));
g[V[i]+1].pb(mp(U[i]+1,W[i]));
sm+= W[i];
}
vector<int> ans;
ans.pb(sm);
ans.pb(sol(1,1));
for(int i = 2; i <= n-1; i++) ans.pb(1);
return ans;
}
Compilation message (stderr)
# | 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... |