# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
626977 | tamthegod | Road Closures (APIO21_roads) | C++14 | 73 ms | 32256 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<bits/stdc++.h>
#include "roads.h"
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
vector<pair<int, int>> adj[maxN];
vector<ll> minimum_closure_costs(int n, vector<int> U, vector<int> V, vector<int> W)
{
vector<ll> res;
bool ok = true;
ll sum = 0;
for(int i=0; i<n-1; i++)
{
int u = U[i] + 1, v = V[i] + 1, w = W[i];
//cout << u << " " << v << '\n';
sum += w;
if(U[i] != i || V[i] != i + 1) ok = false;
adj[u].pb({v, w});
adj[v].pb({u, w});
}
if(adj[1].size() == n - 1)
{
vector<int> vc;
for(int i=0; i<n-1; i++) vc.pb(W[i]);
sort(vc.begin(), vc.end());
for(int i=0; i<n; i++)
{
res.pb(sum);
sum -= vc.back();
vc.pop_back();
}
return res;
}
if(ok)
{
}
}
/*void Solve()
{
int n;
cin >> n;
vector<int> u(n), v(n), w(n);
for(int i=0; i<n-1; i++) cin >> u[i];
for(int i=0; i<n-1; i++) cin >> v[i];
for(int i=0; i<n-1; i++) cin >> w[i];
vector<int> res = minimum_closure_costs(n, u, v, w);
for(int v : res) cout << v << " ";
}
int32_t main()
{
freopen("x.inp", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
Solve();
}*/
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... |