답안 #786642

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
786642 2023-07-18T10:38:33 Z Dan4Life Designated Cities (JOI19_designated_cities) C++17
6 / 100
2000 ms 11548 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define sz(a) (int)a.size()
const int mxN = (int)1e5+10;
int n, q, ans[mxN];
vector<array<int,2>> adj[mxN], tadj[mxN];

void rem(int s, int p){
	for(auto &[u,c] : adj[s]){
		if(u==p) continue;
		c = 0; rem(u,s);
	}
}

int32_t main()
{
	cin >> n; int tot = 0;
	memset(ans,63,sizeof(ans));
	for(int i = 0; i < n-1; i++){
		int a, b, c, d;
		cin >> a >> b >> c >> d; 
		a--,b--,swap(c,d); tot+=c+d;
		adj[a].pb({b,c}); adj[b].pb({a,d});
		tadj[a].pb({b,c}); tadj[b].pb({a,d});
	}
	for(int mask = 0; mask < (1<<n); mask++){
		int sum = 0;
		for(int i = 0; i < n; i++){
			adj[i].clear();
			for(auto u : tadj[i]) adj[i].pb(u);
		}
		for(int i = 0; i < n; i++)
			if((mask>>i)&1) rem(i,-1);
		for(int i = 0; i < n; i++)
			for(auto [b,c] : adj[i]) sum+=c;
		int x = __builtin_popcountll(mask);
		ans[x] = min(ans[x], sum);
	}
	cin >> q;
	while(q--){ int x; cin >> x,cout << ans[x] << "\n";}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5780 KB Output is correct
2 Correct 40 ms 5716 KB Output is correct
3 Correct 52 ms 5776 KB Output is correct
4 Correct 38 ms 5716 KB Output is correct
5 Correct 39 ms 5716 KB Output is correct
6 Correct 39 ms 5716 KB Output is correct
7 Correct 45 ms 5760 KB Output is correct
8 Correct 39 ms 5716 KB Output is correct
9 Correct 36 ms 5780 KB Output is correct
10 Correct 44 ms 5772 KB Output is correct
11 Correct 35 ms 5716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Runtime error 7 ms 11524 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Runtime error 7 ms 11548 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5780 KB Output is correct
2 Correct 40 ms 5716 KB Output is correct
3 Correct 52 ms 5776 KB Output is correct
4 Correct 38 ms 5716 KB Output is correct
5 Correct 39 ms 5716 KB Output is correct
6 Correct 39 ms 5716 KB Output is correct
7 Correct 45 ms 5760 KB Output is correct
8 Correct 39 ms 5716 KB Output is correct
9 Correct 36 ms 5780 KB Output is correct
10 Correct 44 ms 5772 KB Output is correct
11 Correct 35 ms 5716 KB Output is correct
12 Correct 3 ms 5716 KB Output is correct
13 Execution timed out 2078 ms 6100 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Runtime error 7 ms 11524 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5780 KB Output is correct
2 Correct 40 ms 5716 KB Output is correct
3 Correct 52 ms 5776 KB Output is correct
4 Correct 38 ms 5716 KB Output is correct
5 Correct 39 ms 5716 KB Output is correct
6 Correct 39 ms 5716 KB Output is correct
7 Correct 45 ms 5760 KB Output is correct
8 Correct 39 ms 5716 KB Output is correct
9 Correct 36 ms 5780 KB Output is correct
10 Correct 44 ms 5772 KB Output is correct
11 Correct 35 ms 5716 KB Output is correct
12 Correct 3 ms 5716 KB Output is correct
13 Runtime error 7 ms 11524 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -