QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#141519 | #6659. 외곽 순환 도로 2 | penguinman# | Compile Error | / | / | C++17 | 2.6kb | 2023-08-17 15:49:23 | 2024-07-04 01:46:44 |
Judging History
你现在查看的是测评时间为 2024-07-04 01:46:44 的历史记录
- [2024-07-04 01:46:44]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-08-17 15:49:23]
- 提交
answer
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using pii = std::pair<ll,ll>;
#define rep(i,j,k) for(ll i=ll(j); i<ll(k); i++)
#define REP(i,j,k) for(ll i=ll(j); i<=ll(k); i++)
#define per(i,j,k) for(ll i=ll(j); i>=ll(k); i--)
#define ln "\n"
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define mp std::make_pair
#define mtp std::make_tuple
constexpr ll inf = (1ll<<60);
struct union_find{
ll N;
vi par, sz, col;
union_find(ll n): N(n){
par.resize(N);
sz.resize(N,1);
rep(i,0,N) par[i] = i;
col.resize(N);
}
ll root(ll now){
if(par[now] == now) return now;
return root(par[now]);
}
ll color(ll now){
ll ret = 0;
while(true){
if(par[now] == now) break;
ret ^= col[now];
now = par[now];
}
return ret;
}
void merge(ll u, ll v){
ll U = color(u);
ll V = color(v);
u = root(u);
v = root(v);
if(u == v) return;
if(sz[u] > sz[v]){
std::swap(u,v);
std::swap(U,V);
}
sz[v] += sz[u];
sz[u] = 0;
par[u] = v;
if(U == V) col[u] = 1;
}
bool is_ok(ll u, ll v){
if(root(u) != root(v)) return true;
if(color(u) == color(v)) return false;
return true;
}
bool same(ll u, ll v){
return root(u) == root(v);
}
};
long long place_police(vector<int> P, vector<long long> C, vector<long long> W){
ll N = P.size()+1;
ll K = W.size();
vi u(N+K-1), v(N+K-1), w(N+K-1);
{
vi cnt(N);
rep(i,1,N){
u[i-1] = P[i-1];
v[i-1] = i;
w[i-1] = C[i-1];
cnt[P[i-1]]++;
}
vi V;
rep(i,0,N){
if(cnt[i]) continue;
V.pb(i);
}
assert(V.size() == K);
rep(i,0,K){
u[N-1+i] = V[i];
v[N-1+i] = V[(i+1)%K];
w[N-1+i] = W[i];
}
}
ll M = N+K-1;
vector<std::tuple<ll,ll,ll>> data(M);
rep(i,0,M) data[i] = mtp(w[i], u[i], v[i]);
sort(all(data));
reverse(all(data));
union_find tree(N);
ll ans = 0;
for(auto el: data){
ll val, x, y;
std::tie(val, x, y) = el;
if(tree.is_ok(x,y)){
tree.merge(x,y);
}
else{
ans += val;
}
}
return ans;
}
详细
cc1plus: fatal error: implementer.cpp: No such file or directory compilation terminated.