제출 #554192

#제출 시각아이디문제언어결과실행 시간메모리
554192Zhora_004도로 폐쇄 (APIO21_roads)C++17
12 / 100
2068 ms11460 KiB
#include "roads.h" #include <iostream> #include <cmath> #include <algorithm> #include <vector> #include <set> #include <unordered_set> #include <queue> #include <deque> #include <string> #include <sstream> #include <iomanip> #include <map> #include <unordered_map> #include <stack> #include <cstdio> #include <climits> #include <tuple> #include <ctime> #include <cstring> #include <numeric> #include <functional> #include <chrono> #include <cassert> #include <bitset> #include <fstream> //#include <bit> //#include <ranges> //#include <numbers> #define sz(a) ((int)((a).size())) // printf("%.10f\n", ans); /*ofstream fout("timeline.out"); ifstream fin("timeline.in");*/ using ll = long long; using namespace std; int n; vector<int> a, b, c; struct Edge { int u, v, w; }; bool comp(Edge& e1, Edge& e2) { return e1.w < e2.w; } bool task(int id) { if (id == 1) { for (int& i : a) if (i) return 0; return 1; } if (id == 2) { for (int i = 0; i < n - 1; i++) if (a[i] != i || b[i] != i + 1) return 0; return 1; } return 0; } std::vector<long long> minimum_closure_costs(int N, std::vector<int> U, std::vector<int> V, std::vector<int> W) { n = N; a = U; b = V; c = W; if (task(1)) { vector<ll> res; ll sum = 0; for (int& i : c) sum += i; res.push_back(sum); sort(c.begin(), c.end()); reverse(c.begin(), c.end()); for (int k = 0; k < n - 1; k++) { sum -= c[k]; res.push_back(sum); } return res; } if (task(2)) { ll sum = 0; vector<vector<ll>> dp(n, vector<ll>(2)); for (int i = 1; i < n; i++) { dp[i][0] = dp[i - 1][1]; dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + c[i - 1]; sum += c[i - 1]; } vector<ll> res; res.push_back(sum); res.push_back(min(dp[n - 1][0], dp[n - 1][1])); for (int k = 2; k < n; k++) res.push_back(0); return res; } else { vector<Edge> edges(n - 1); for (int i = 0; i < n - 1; i++) { edges[i].u = a[i]; edges[i].v = b[i]; edges[i].w = c[i]; } sort(edges.begin(), edges.end(), comp); vector<ll> res; for (int k = 0; k < n; k++) { ll sum = 0; vector<int> deg(n); for (int i = 0; i < n - 1; i++) { deg[a[i]]++; deg[b[i]]++; } for (int i = 0; i < n - 1; i++) { int u = a[i], v = b[i], w = c[i]; if (deg[u] > k || deg[v] > k) { sum += w; deg[u]--; deg[v]--; } } res.push_back(sum); } return res; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...