답안 #563041

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
563041 2022-05-16T06:16:05 Z Devigo 도로 폐쇄 (APIO21_roads) C++14
0 / 100
2000 ms 6176 KB
#include <bits/stdc++.h>
using namespace std;

const int siz = 1e5+1;
bool done = 0;

long long cost = 0;

vector<bool> rem(siz,0);

struct edge {
	long long w, x, y;
};

bool cmp (edge a, edge b) {
	return a.w < b.w;
}

void get(int k, vector<int> &degree, vector<edge> &el, int n, int m) {
	for(int i=0; i<m; i++) {
		if(rem[i]) continue;
		bool isb = 0;
		int u = degree[el[i].x]; int v = degree[el[i].y];
		if(u > k || v > k) isb = 1;
		if(isb) {
			degree[el[i].x]--; degree[el[i].y]--;
			rem[i] = 1;
			cost += el[i].w;
		}
		int grt = -1;
		for(int j=0; j<n; j++) {
			grt = max(grt,degree[j]);
		}
		if(grt <= k) {
			done = 1; return;
		}
	}
	int g = -1;
	for(int j=0; j<n; j++) {
		g = max(g,degree[j]);
	}
	if(g <= k) done = 1;
	return;
}

vector<long long> minimum_closure_costs(int n, vector<int> u, vector<int> v, vector<int> w) {
	vector<int> degree(n,0);
	vector<edge> el;
	int m = n-1;
	for(int i=0; i<m; i++) {
		degree[u[i]]++;
		degree[v[i]]++;
		el.push_back({w[i],u[i],v[i]});
	}
	sort(el.begin(), el.end(), cmp);
	vector<long long> c(n); 
	for(int i=m; i>=0; i--) {
		while(!done) {
			get(i,degree,el,n,m);
		}
		c[i] = cost;
		done = 0;
	}
	return c;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 8 ms 468 KB Output is correct
3 Correct 7 ms 468 KB Output is correct
4 Correct 7 ms 468 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 5 ms 444 KB Output is correct
9 Correct 7 ms 460 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Execution timed out 2084 ms 3776 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 2090 ms 5772 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2083 ms 6176 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2083 ms 6176 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 8 ms 468 KB Output is correct
3 Correct 7 ms 468 KB Output is correct
4 Correct 7 ms 468 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 5 ms 444 KB Output is correct
9 Correct 7 ms 460 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Execution timed out 2084 ms 3776 KB Time limit exceeded
13 Halted 0 ms 0 KB -