QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#116216 | #6659. 외곽 순환 도로 2 | lcjlcj# | Compile Error | / | / | C++20 | 5.0kb | 2023-06-28 12:19:01 | 2024-05-31 18:21:18 |
Judging History
你现在查看的是测评时间为 2024-05-31 18:21:18 的历史记录
- [2024-05-31 18:21:18]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2023-06-28 12:19:01]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5,intinf=1e9;
const long long longlonginf=1e18;
int n,K;
vector<pair<int,long long>> g[maxn+5];
long long f[maxn+5][2][2][2];
int dep[maxn+5],Leafpos[maxn+5],leaf;
int Lp[maxn+5],Rp[maxn+5];
long long place_police(vector<int> P,vector<long long> C,vector<long long> W) {
n=P.size()+1;
K=W.size();
for (int i=0;i<n-1;i++) {
g[P[i]].emplace_back(i+1,C[i]);
}
function<void(int)> dfs0=[&](int u) {
if (!g[u].size()) {
Leafpos[leaf]=dep[u]&1;
Lp[u]=leaf;
Rp[u]=leaf++;
}
else Lp[u]=intinf,Rp[u]=-intinf;
for (auto [v,w]:g[u]) {
dep[v]=dep[u]+1;
dfs0(v);
Lp[u]=min(Lp[u],Lp[v]);
Rp[u]=max(Rp[u],Rp[v]);
}
} ;
dfs0(0);
for (int i=0;i<n;i++) {
for (int o=0;o<2;o++) {
for (int p=0;p<2;p++) {
for (int q=0;q<2;q++) {
f[i][o][p][q]=longlonginf;
}
}
}
}
auto chkmn=[&](long long &x,long long y) {
x=min(x,y);
} ;
function<void(int)> dfs1=[&](int u) {
if (!g[u].size()) {
f[u][1][1][0]=0;
return ;
}
for (auto [v,w]:g[u]) dfs1(v);
int firv=g[u][0].first;
long long firw=g[u][0].second;
for (int i=0;i<2;i++) {
for (int j=0;j<2;j++) {
for (int k=0;k<2;k++) {
if (f[firv][i][j][k]==longlonginf) continue ;
chkmn(f[u][i][j][k],f[firv][i][j][k]);
chkmn(f[u][0][0][k],f[firv][i][j][k]+firw);
}
}
}
int lstrp=Rp[firv];
long long tmpf[2][2][2]={};
for (int j=1;j<g[u].size();j++) {
int v=g[u][j].first; long long w=g[u][j].second;
for (int i=0;i<2;i++) for (int j=0;j<2;j++) for (int k=0;k<2;k++) {
tmpf[i][j][k]=longlonginf;
}
for (int ul=0;ul<2;ul++) {
for (int ur=0;ur<2;ur++) {
for (int vl=0;vl<2;vl++) {
for (int vr=0;vr<2;vr++) {
for (int o=0;o<2;o++) {
for (int p=0;p<2;p++) {
for (int q=0;q<2;q++) {
if (f[u][ul][ur][o]==longlonginf) continue ;
if (f[v][vl][vr][p]==longlonginf) continue ;
int nvl=vl,nvr=vr;
long long vw=0;
if (q==0) nvl=nvr=0,vw=w;
for (int k=0;k<2;k++) {
long long vk=0;
if (k==1) vk=W[lstrp];
if (ur && nvl && Leafpos[lstrp]==Leafpos[Lp[v]] && !k) continue ;
else chkmn(tmpf[ul][nvr][o|p|k],f[u][ul][ur][o]+f[v][vl][vr][p]+vw+vk);
}
}
}
}
}
}
}
}
for (int i=0;i<2;i++) for (int j=0;j<2;j++) for (int k=0;k<2;k++) f[u][i][j][k]=tmpf[i][j][k];
lstrp=Rp[v];
}
if (Lp[u]==0 && Rp[u]==K-1) {
for (int i=0;i<2;i++) for (int j=0;j<2;j++) for (int k=0;k<2;k++) {
tmpf[i][j][k]=longlonginf;
}
for (int i=0;i<2;i++) {
for (int j=0;j<2;j++) {
for (int k=0;k<2;k++) {
for (int o=0;o<2;o++) {
long long kw=0;
if (o==1) kw=W[K-1];
if (i && j && Leafpos[Lp[u]]==Leafpos[Rp[u]] && !k) continue ;
chkmn(tmpf[i][j][k|o],f[u][i][j][k]+kw);
}
}
}
}
for (int i=0;i<2;i++) for (int j=0;j<2;j++) for (int k=0;k<2;k++) f[u][i][j][k]=tmpf[i][j][k];
}
} ;
dfs1(0);
long long ans=longlonginf;
for (int i=0;i<2;i++) {
for (int j=0;j<2;j++) {
for (int k=0;k<2;k++) {
if (K%2==1 && k==0) continue ;
ans=min(ans,f[0][i][j][k]);
}
}
}
return ans;
}
/*
int main() {
ios::sync_with_stdio(0);
vector<int> P;
vector<long long> C,W;
cin.tie(0);
cin>>n>>K;
P.resize(n-1); C.resize(n-1); W.resize(K);
for (int i=0;i<n-1;i++) cin>>P[i];
for (int i=0;i<n-1;i++) cin>>C[i];
cerr<<K<<'\n';
for (int i=0;i<K;i++) cin>>W[i];
cout<<place_police(P,C,W)<<'\n';
return 0;
}
*/
Details
cc1plus: fatal error: implementer.cpp: No such file or directory compilation terminated.