QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#141519 | #6659. 외곽 순환 도로 2 | penguinman# | 0 | 32ms | 19312kb | C++17 | 2.6kb | 2023-08-17 15:49:23 | 2024-08-26 15:51:17 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 6
Accepted
time: 0ms
memory: 3868kb
input:
5 0 452912 0 820899 0 79369 0 232463 1000000000000 1000000000000 1000000000000 1000000000000
output:
532281
result:
ok single line: '532281'
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 3804kb
input:
6 0 581451 0 68556 0 918465 0 661406 0 41816 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000
output:
1000001311413
result:
wrong answer 1st lines differ - expected: '1000000110372', found: '1000001311413'
Subtask #2:
score: 0
Wrong Answer
Test #28:
score: 8
Accepted
time: 32ms
memory: 19312kb
input:
99997 0 122727 0 267270 0 846212 0 454122 0 805668 0 614161 0 7805 0 173284 0 684707 0 269129 0 930945 0 1101 0 992427 0 297412 0 759787 0 227130 0 120418 0 90914 0 333684 0 46144 0 519912 0 171490 0 823586 0 121787 0 674177 0 560254 0 753090 0 853359 0 465464 0 655527 0 631303 0 919012 0 597126 0 1...
output:
24980330181
result:
ok single line: '24980330181'
Test #29:
score: 8
Accepted
time: 23ms
memory: 19232kb
input:
99997 0 122727 0 267270 0 846212 0 454122 0 805668 0 614161 0 7805 0 173284 0 684707 0 269129 0 930945 0 1101 0 992427 0 297412 0 759787 0 227130 0 120418 0 90914 0 333684 0 46144 0 519912 0 171490 0 823586 0 121787 0 674177 0 560254 0 753090 0 853359 0 465464 0 655527 0 631303 0 919012 0 597126 0 1...
output:
24980330181
result:
ok single line: '24980330181'
Test #30:
score: 0
Wrong Answer
time: 27ms
memory: 19236kb
input:
99998 0 792854 0 622829 0 836127 0 847372 0 71732 0 241096 0 487224 0 696890 0 899047 0 845614 0 27226 0 270985 0 698890 0 64699 0 856738 0 685434 0 766150 0 540443 0 802763 0 874879 0 250532 0 834015 0 616087 0 771638 0 262098 0 458015 0 959723 0 408130 0 880649 0 456673 0 923653 0 969100 0 439032 ...
output:
1025077589459
result:
wrong answer 1st lines differ - expected: '1025006589524', found: '1025077589459'
Subtask #3:
score: 0
Wrong Answer
Test #36:
score: 5
Accepted
time: 0ms
memory: 3820kb
input:
11 0 9 0 8 2 0 3 7 3 1 2 6 0 0 7 7 7 1 9 6 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000
output:
1
result:
ok single line: '1'
Test #37:
score: 0
Wrong Answer
time: 12ms
memory: 8076kb
input:
50311 0 630582 1 458618 2 300543 3 566041 4 306718 5 134260 6 736322 7 458543 8 609374 9 355623 10 706939 11 48588 12 455725 13 105118 14 71071 15 528699 16 423538 17 471781 18 98063 19 169099 20 657181 21 295537 22 49937 23 306612 24 186582 25 505763 26 831500 27 406268 28 294626 29 128111 30 42115...
output:
1088276
result:
wrong answer 1st lines differ - expected: '813491', found: '1088276'
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #77:
score: 0
Wrong Answer
time: 13ms
memory: 8280kb
input:
50311 0 962897543825 1 887020369743 2 363658802934 3 481009844166 4 1099712574 5 858320882162 6 521927434762 7 379344260539 8 73024776148 9 634183458545 10 869560347910 11 81581323331 12 750044298516 13 307013017409 14 306226274039 15 423923546601 16 482114694167 17 849292461119 18 299993045938 19 7...
output:
1093638137315
result:
wrong answer 1st lines differ - expected: '939418184213', found: '1093638137315'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%