QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#307578#6659. 외곽 순환 도로 2DualqwqCompile Error//C++201.8kb2024-01-18 20:43:472024-01-18 20:43:47

Judging History

你现在查看的是测评时间为 2024-01-18 20:43:47 的历史记录

  • [2024-08-26 15:51:47]
  • 管理员手动重测本题所有提交记录
  • 测评结果:8
  • 用时:33ms
  • 内存:29540kb
  • [2024-01-18 20:43:47]
  • 评测
  • [2024-01-18 20:43:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
template<typename T> inline bool ckmin(T &x,const T &y) { return (x > y) && (x = y,true);}
typedef long long ll;
typedef pair<int,ll> pii;
#define FI first
#define SE second
#define mkp make_pair
int n,K;
vector<pii> G[N];
ll dp[N][2][2][2];
int L[N],R[N];
ll W[N];

void dfs0(int x,int fa) {
	if(G[x].size() == 0) { L[x] = R[x] = ++L[0];return;}
	for(auto [y,w] : G[x]) {
		if(y == fa) continue;
		dfs0(y,x);
		L[x] = min(L[x],L[y]);
		R[x] = max(R[x],R[y]);
	}
}
void dfs1(int x,int fa) {
	memset(dp[x],0x3f,sizeof dp[x]);
	if(G[x].size() == 0) { dp[x][0][0][0] = dp[x][1][1][1] = 0;return;}
	bool lst = 0;

	for(auto [y,w] : G[x]) {
		if(y == fa) continue;
		dfs1(y,x);
		if(!lst) {
			for(int a = 0;a < 2;a++)
				for(int b = 0;b < 2;b++)
					for(int c = 0;c < 2;c++)
						for(int d = 0;d < 2;d++)
							ckmin(dp[x][a][c][d],dp[y][b][c][d] + (a == b) * w);
			lst = 1;
		} else {
			ll tmp[2][2][2];
			memset(tmp,0x3f,sizeof tmp);
			for(int a = 0;a < 2;a++)
				for(int b = 0;b < 2;b++)
					for(int c = 0;c < 2;c++)
						for(int d = 0;d < 2;d++)
							for(int e = 0;e < 2;e++)
								for(int f = 0;f < 2;f++)
				ckmin(tmp[a][b][f],dp[x][a][b][c] + dp[y][d][e][f] + (c == e) * W[L[y] - 1] + (a == d) * w);
			for(int a = 0;a < 2;a++)
				for(int b = 0;b < 2;b++)
					for(int c = 0;c < 2;c++)
						dp[x][a][b][c] = tmp[a][b][c];
		}
	}
}
ll place_police(vector<int> P,vector<ll> C,vector<ll> _W) {
	n = P.size() + 1;K = _W.size();
	for(int i = 2;i <= n;i++)
		G[P[i - 2] + 1].emplace_back(i,C[i - 2]);
	for(int i = 1;i <= K;i++) W[i] = _W[i - 1];
	dfs0(1,0);
	dfs1(1,0);
	long long ans = 4e18;
	for(int a = 0;a < 2;a++)
		for(int b = 0;b < 2;b++)
			for(int c = 0;c < 2;c++)
				ckmin(ans,dp[1][a][b][c] + (b == c) * W[K]);
	return ans;
}

详细

cc1plus: fatal error: implementer.cpp: No such file or directory
compilation terminated.