답안 #677585

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
677585 2023-01-03T20:16:29 Z YENGOYAN 도로 폐쇄 (APIO21_roads) C++17
0 / 100
381 ms 1048576 KB
#include "roads.h"
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_map>
#include <cmath>
#include <climits>
#include <algorithm>
#include <random>
#include <queue>
#include <deque>
#include <iomanip>
#include <string>
#include <tuple>
#include <bitset>
#include <chrono>
#include <ctime>
#include <fstream>
#include <stack>
#include <cstdio>
using namespace std;
using ll = long long;

vector<vector<pair<int, int>>> gp;
vector<vector<ll>> dp;

void dfs(int u, int p, int k) {
	vector<ll> vec;
	for (pair<int, int>& v : gp[u]) {
		if (v.first == p) continue;
		dfs(v.first, u, k);
		dp[u][k] += dp[v.first][k];
		vec.push_back(max(0ll, dp[v.first][k - 1] + v.second - dp[v.first][k]));
	}
	//dp[u][0] =
	sort(vec.rbegin(), vec.rend());
	for (int i = 0; i < min(int(vec.size()), k); ++i) dp[u][k] += vec[i];
}


vector<ll> minimum_closure_costs(int n, vector<int> U,vector<int> V,vector<int> W) {
	gp = vector<vector<pair<int, int>>>(n);
	dp = vector<vector<ll>>(n, vector<ll>(n));
	ll sm = 0;
	for (int i = 0; i < n - 1; ++i) {
		gp[U[i]].push_back({ V[i], W[i] });
		gp[V[i]].push_back({ U[i], W[i] });
		sm += W[i];
	}
	vector<ll> vec(n);
	vec[0] = sm;
	for (int i = 1; i < n; ++i) {
		dfs(0, -1, i);
		vec[i] = sm - dp[0][i];
	}
	return vec;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 210 ms 28272 KB Output is correct
3 Correct 238 ms 31916 KB Output is correct
4 Correct 142 ms 31920 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 106 ms 22760 KB Output is correct
9 Correct 167 ms 31920 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Runtime error 375 ms 1048576 KB Execution killed with signal 9
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 381 ms 1048576 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Incorrect 2 ms 468 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Incorrect 2 ms 468 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 368 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 368 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 210 ms 28272 KB Output is correct
3 Correct 238 ms 31916 KB Output is correct
4 Correct 142 ms 31920 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 106 ms 22760 KB Output is correct
9 Correct 167 ms 31920 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Runtime error 375 ms 1048576 KB Execution killed with signal 9
13 Halted 0 ms 0 KB -