QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#308212#6659. 외곽 순환 도로 2SampsonYWCompile Error//C++141.9kb2024-01-19 18:53:452024-01-19 18:53:46

Judging History

你现在查看的是测评时间为 2024-01-19 18:53:46 的历史记录

  • [2024-08-26 15:51:59]
  • 管理员手动重测本题所有提交记录
  • [2024-01-19 18:53:46]
  • 评测
  • [2024-01-19 18:53:45]
  • 提交

answer

#include <bits/stdc++.h>
#define il inline
#define re register
#define ll long long
#define pii pair<int, int>
#define fi first
#define se second
#define eb emplace_back
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(), v.end()
using namespace std;
#define N 100005
il void chkmin(ll &x, ll y) {(x > y) && (x = y);}
int n, m; ll v[N];
vector<pair<int, ll>> son[N];
ll dp[N][2][2][2], tmp[2][2][2];
#define FOR(i, L, R) for(re int i = (L); i <= (R); ++i)
#define FR(a, b, c) FOR(a, 0, 1) FOR(b, 0, 1) FOR(c, 0, 1)
il void dfs(int x) {  
  if(son[x].empty()) {
    FOR(k, 0, 1) dp[x][k][k][k] = 0; ++m; return ;
  }
  bool F = 0; ll d;
  for(auto it : son[x]) {
    int y = it.fi; ll w = it.se; dfs(y);
    memcpy(tmp, dp[x], sizeof(tmp));
    memset(dp[x], 0x7f / 2, sizeof(dp[x]));
    if(!F) FOR(A, 0, 1) FR(a, b, c)
      chkmin(dp[x][A][b][c], dp[y][a][b][c] + (A == a) * w);
    else FR(A, B, C) FR(a, b, c)
      chkmin(dp[x][A][B][c], tmp[A][B][C] + dp[y][a][b][c] + (A == a) * w + (C == b) * d);
    F = 1, d = v[m];
    // cerr << "edge " << x << " " << y << " " << d << "\n";
  }
}
long long place_police(vector<int> P, vector<long long> C, vector<long long> W) {
  n = SZ(P) + 1;
  for(re int i = 0; i < n - 1; ++i)
    son[P[i] + 1].eb(i + 2, C[i]);
    // cerr << P[i] + 1 << " " << i + 2 << " " << C[i] << "\n";
  for(auto x : W) v[++m] = x;
  memset(dp, 0x7f / 2, sizeof(dp));
  m = 0, dfs(1); ll ans = 1e18;
  // cerr << m << "\n";
  // FOR(x, 1, n) FR(a, b, c) cerr << x << "," << a << "," << b << "," << c << " = " << dp[x][a][b][c] << "\n";
  FR(a, b, c) chkmin(ans, dp[1][a][b][c] + (b == c) * v[m]);
  return ans;
}
int main() {
  int n; cin >> n;
  vector<int> P(n - 1);
  vector<ll> C(n - 1), W;
  for(re int i = 0; i < n - 1; ++i)
    cin >> P[i] >> C[i];
  ll x; while(cin >> x) W.eb(x);
  cout << place_police(P, C, W);
  cerr << 1.0 * clock() / CLOCKS_PER_SEC;
}

详细

/usr/bin/ld: /tmp/ccWJIx8F.o: in function `main':
answer.code:(.text.startup+0x0): multiple definition of `main'; /tmp/ccFqjgtF.o:implementer.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status