QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#406621#6659. 외곽 순환 도로 2socpiteCompile Error//C++232.6kb2024-05-07 15:19:042024-08-26 15:52:19

Judging History

你现在查看的是最新测评结果

  • [2024-08-26 15:52:19]
  • 管理员手动重测本题所有提交记录
  • [2024-05-07 15:19:07]
  • 评测
  • [2024-05-07 15:19:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int maxn = 1e5+5;
const long long INF = 1e18;

vector<int> g[maxn];

long long dp[maxn][2][2][2];
int R[maxn];
long long w[maxn], c[maxn];

void dfs(int x, int &cnt){
    if(g[x].empty()){
        for(int i = 0; i < 2; i++){
            for(int j = 0; j < 2; j++){
                for(int k = 0; k < 2; k++){
                    dp[x][i][j][k] = INF;
                }
            }
        }
        dp[x][0][0][0] = dp[x][1][1][1] = 0;
        R[x] = ++cnt;
        return;
    }
    for(auto v: g[x]){
        dfs(v, cnt);
        if(!R[x]){
            for(int i = 0; i < 2; i++){
                for(int j = 0; j < 2; j++){
                    for(int k = 0; k < 2; k++){
                        dp[x][i][j][k] = min(dp[v][i][j][k] + c[v], dp[v][i^1][j][k]);
                    }
                }
            }
        }
        else {
            long long nw[2][2][2];
            for(int xc = 0; xc < 2; xc++){
                for(int xl = 0; xl < 2; xl++){
                    for(int xr = 0; xr < 2; xr++){
                        nw[xc][xl][xr] = INF;
                    }
                }
            }
            for(int xc = 0; xc < 2; xc++){
                for(int xl = 0; xl < 2; xl++){
                    for(int xr = 0; xr < 2; xr++){
                        for(int vc = 0; vc < 2; vc++){
                            for(int vl = 0; vl < 2; vl++){
                                for(int vr = 0; vr < 2; vr++){
                                    nw[xc][xl][vr] = min(nw[xc][xl][vr], dp[x][xc][xl][xr] + dp[v][vc][vl][vr] + c[v]*(vc == xc) + w[R[x]]*(xr == vl));
                                }
                            }
                        }
                    }
                }
            }
            for(int xc = 0; xc < 2; xc++){
                for(int xl = 0; xl < 2; xl++){
                    for(int xr = 0; xr < 2; xr++){
                        dp[x][xc][xl][xr] = nw[xc][xl][xr];
                    }
                }
            }
        }
        R[x] = R[v];
    }
}

long long place_police (vector<int> P, vector<long long> C, vector<long long> W){
    for(int i = 0; i < W.size(); i++)w[i+1] = W[i];
    for(int i = 0; i < P.size(); i++){
        g[P[i]].push_back(i+1);
        c[i+1] = C[i];
    }
    dfs(0, 0);
    long long ans = INF;
    for(int xc = 0; xc < 2; xc++){
        for(int xl = 0; xl < 2; xl++){
            for(int xr = 0; xl < 2; xl++){
                ans = min(ans, dp[0][xc][xl][xr] + w[R[0]]*(xl == xr));
            }
        }
    }
    return ans;
}

详细

answer.code: In function ‘long long int place_police(std::vector<int>, std::vector<long long int>, std::vector<long long int>)’:
answer.code:77:12: error: cannot bind non-const lvalue reference of type ‘int&’ to an rvalue of type ‘int’
   77 |     dfs(0, 0);
      |            ^
answer.code:13:22: note:   initializing argument 2 of ‘void dfs(int, int&)’
   13 | void dfs(int x, int &cnt){
      |                 ~~~~~^~~