QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#555500 | #436. Swapping Cities | makrav | 0 | 81ms | 36288kb | C++20 | 4.5kb | 2024-09-10 01:16:25 | 2024-09-10 01:16:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define pb push_back
const int MAXN = 100010;
const int INF = 1e9 + 1;
struct dsu {
int n;
vector<int> par, siz, isb, moment;
vector<vector<int>> sub;
vector<pair<int, int>> bamboo;
dsu() = default;
dsu(int n_) {
n = n_;
par.assign(n, 0);
siz.assign(n, 1);
moment.assign(n, INF);
isb.assign(n, 1);
sub.resize(n);
for (int i = 0; i < n; i++) {
sub[i].pb(i);
bamboo.pb({i, i});
}
iota(all(par), 0);
}
int get(int v) {return (par[v] == v ? v : par[v] = get(par[v]));}
bool merge(int u, int v, int W) {
int oru = u, orv = v;
u = get(u); v = get(v);
if (u == v) {
if (isb[u]) {
isb[u] = 0;
for (int U : sub[u]) {
moment[U] = W;
}
}
return false;
}
bool new_not_bamboo = (!isb[u] || !isb[v] || (oru != bamboo[u].first && oru != bamboo[u].second) || (orv != bamboo[v].first && orv != bamboo[v].second));
if (new_not_bamboo && isb[u]) {
for (int U : sub[u]) moment[U] = W;
}
if (new_not_bamboo && isb[v]) {
for (int U : sub[v]) moment[U] = W;
}
if (siz[u] < siz[v]) swap(u, v);
par[v] = u;
siz[u] += siz[v];
for (auto &U : sub[v]) {
sub[u].pb(U);
}
sub[v].clear();
isb[u] = !new_not_bamboo;
if (isb[u]) {
map<int, int> cnt;
cnt[bamboo[u].first]++;cnt[bamboo[u].second]++;
cnt[bamboo[v].first]++;cnt[bamboo[v].second]++;
set<int> st;
vector<int> xd = {u, v};
for (int vt : xd) {
if(cnt[bamboo[vt].first] - (bamboo[vt].first == oru) - (bamboo[vt].first == orv) == 1) st.insert(bamboo[vt].first);
if(cnt[bamboo[vt].second] - (bamboo[vt].second == oru) - (bamboo[vt].second == orv) == 1) st.insert(bamboo[vt].second);
}
bamboo[u] = {*st.begin(), *st.rbegin()};
}
return true;
}
};
vector<int> gt[MAXN];
int up[17][MAXN], h[MAXN], tin[MAXN], tout[MAXN], tim = 0;
// up2 for bridges, up3 for some edge out
void dfs(int v, int p) {
tin[v] = tim++;
up[0][v] = p;
for (int i = 1; i < 17; i++) {
up[i][v] = up[i - 1][up[i - 1][v]];
}
for (int u : gt[v]) {
if (u != p) {
h[u] = h[v] + 1;
dfs(u, v);
}
}
tout[v] = tim++;
}
bool par(int u, int v) {
return tin[u] <= tin[v] && tout[v] <= tout[u];
}
int lca(int u, int v) {
if (par(u, v)) return u;
if (par(v, u)) return v;
for (int i = 16; i >= 0; i--) {
if (!par(up[i][v], u)) v = up[i][v];
}
return up[0][v];
}
int dist(int u, int v) {return h[u] + h[v] - 2 * h[lca(u, v)];}
vector<pair<int, int>> gtt[MAXN];
int up101[17][MAXN];
void dfs2(int v, int p, int inw) {
up101[0][v] = inw;
for (int i = 1; i < 17; i++) {
up101[i][v] = max(up101[i - 1][v], up101[i - 1][up[i - 1][v]]);
}
for (auto &[u, w] : gtt[v]) {
if (u != p) {
dfs2(u, v, w);
}
}
}
vector<int> FUCKFUCK;
int get_maxw_on_path(int u, int v) {
int lc = lca(u, v);
int ans = 0;
for (int i = 0; i < 17; i++) {
if (((h[u] - h[lc]) >> i) & 1) {
ans = max(ans, up101[i][u]);
u = up[i][u];
}
}
for (int i = 0; i < 17; i++) {
if (((h[v] - h[lc]) >> i) & 1) {
ans = max(ans, up101[i][v]);
v = up[i][v];
}
}
return ans;
}
void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
vector<int> ord(M);
iota(all(ord), 0);
sort(all(ord), [&](int i, int j){
return W[i] < W[j];
});
dsu d(N);
vector<int> ev;
for (int i = 0; i < M; i++) {
if (d.merge(U[ord[i]], V[ord[i]], W[ord[i]])) {
gtt[U[ord[i]]].pb({V[ord[i]], W[ord[i]]});
gtt[V[ord[i]]].pb({U[ord[i]], W[ord[i]]});
}
}
FUCKFUCK = d.moment;
dfs(0, 0);
dfs2(0, 0, 0);
}
int getMinimumFuelCapacity(int X, int Y) {
int A1 = max(FUCKFUCK[X], FUCKFUCK[Y]);
int A3 = get_maxw_on_path(X, Y);
if(max(A1, A3) == 588185226) assert(A3 == 588185226);
return (max(A1, A3) == INF ? -1 : max(A1, A3));
}
詳細信息
Subtask #1:
score: 0
Accepted
Test #1:
score: 0
Accepted
time: 3ms
memory: 16068kb
input:
2 1 0 1 7 1 0 1
output:
-1
result:
ok single line: '-1'
Subtask #2:
score: 0
Accepted
Test #3:
score: 0
Accepted
time: 0ms
memory: 16408kb
input:
3 2 0 1 17 1 2 31 4 0 1 1 2 0 2 0 1
output:
-1 -1 -1 -1
result:
ok 4 lines
Subtask #3:
score: 0
Accepted
Test #9:
score: 0
Accepted
time: 62ms
memory: 33840kb
input:
78487 78486 21940 24079 593765451 9058 50840 275027221 12096 22343 27089177 43977 52298 190799385 5430 49666 122910535 1966 50992 106732940 22047 65169 949810064 27980 65052 751605553 15372 20060 848481254 38243 77115 484610983 61070 66606 631024623 6943 50841 979259732 42129 51057 828673666 50591 6...
output:
-1 -1
result:
ok 2 lines
Subtask #4:
score: 0
Accepted
Test #14:
score: 0
Accepted
time: 76ms
memory: 33936kb
input:
78254 78253 9775 28301 780798184 24132 40634 94556968 10169 55532 346574336 2603 65541 873326115 22699 58466 669409812 16474 42626 302001067 15127 56693 625109610 64811 67816 578907024 46689 60091 972201244 27305 39328 642009505 12305 64823 890024771 14652 41221 804727810 14493 38064 692491627 39467...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 18751 lines
Subtask #5:
score: 0
Accepted
Test #19:
score: 0
Accepted
time: 81ms
memory: 36288kb
input:
94623 94622 0 75305 622253738 0 54796 462724128 0 75886 137979635 0 66452 665511713 0 64781 420871714 0 2628 102391513 0 74571 844600388 0 76649 57731825 0 36212 950028495 0 47294 149834685 0 28114 545648033 0 56460 673370408 0 66350 337337539 0 18222 283237145 0 72426 916482721 0 57766 119923766 0 ...
output:
860148668 999773640 548578490 665594696 855392447 897265657 892048171 845668166 355156446 277230669 913611642 453737557 492253954 853354202 989302450 974664128 857227765 280875614 845329631 943817066 884159669 715125377 852337346 939409087 937559913 551196227 555263380 881942828 583059294 196822146 ...
result:
ok 189713 lines
Subtask #6:
score: 0
Runtime Error
Test #27:
score: 0
Runtime Error
input:
990 989 47 838 302271558 273 492 664559881 148 815 976564144 331 495 44254198 669 820 218690102 188 882 677033947 643 698 971006957 488 729 679293846 256 281 332371780 127 771 383138407 134 679 846068552 596 599 203286566 613 941 328910657 432 852 151755209 145 463 456917162 0 71 752175798 152 789 8...
output:
Unauthorized output
result:
Subtask #7:
score: 0
Wrong Answer
Test #36:
score: 0
Wrong Answer
time: 7ms
memory: 18628kb
input:
13604 13603 8356 8403 796466173 5628 8429 906962701 3920 11930 959959178 6663 6830 290048491 915 9376 663274411 8722 13162 195512431 2211 6043 263205971 8174 13268 998861827 10074 10858 784154000 8290 11604 141391920 20 7972 249696621 3338 4649 65522585 3608 11223 132978393 2265 5109 973339144 5136 ...
output:
780119208
result:
wrong answer 1st lines differ - expected: '997836405', found: '780119208'
Subtask #8:
score: 0
Wrong Answer
Test #47:
score: 0
Wrong Answer
time: 6ms
memory: 18572kb
input:
12312 12311 2916 8085 175102149 1475 6850 309919528 6782 9694 260794553 2517 8281 584952046 4250 7806 662855436 412 9797 731092675 6802 9405 845105258 3077 10964 132387860 225 5421 28087274 1741 11558 107203447 4227 11940 313968264 4567 6286 246562765 8712 9079 851022380 6136 7008 430961650 3459 540...
output:
809354778 744339962 546533473 908280453 764916506 907655361 843320671 623389238 880350273 610970078 505612216 952033585 941874506 728379068 934681066 931847368 803236318 969886835 672164807 714420435 697880220 827967796 594265625 786471346 870232818 524159444 949106059 949106059 801563381 565372056 ...
result:
wrong answer 1st lines differ - expected: '924041708', found: '809354778'
Subtask #9:
score: 0
Accepted
Test #58:
score: 0
Accepted
time: 44ms
memory: 20768kb
input:
15780 15780 9590 14917 123113565 8122 11966 171896575 4538 9640 684944907 310 15055 407333658 6468 6696 360870061 14420 14762 755531343 1519 7305 780579452 4826 10759 449674098 962 6310 894674872 1063 3895 307635821 1732 6606 796058884 9844 13284 963137200 3006 11229 839846442 9699 12787 436669041 3...
output:
999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 999989524 ...
result:
ok 159998 lines
Subtask #10:
score: 0
Accepted
Test #63:
score: 0
Accepted
time: 3ms
memory: 16252kb
input:
700 981 98 105 341789735 208 604 709973200 335 644 104865354 338 602 812201660 343 518 643785882 573 628 351487907 34 371 52914687 309 353 606226854 279 656 985748970 225 364 196001300 31 40 990562200 355 510 995899482 258 663 316091802 270 314 981972681 39 383 327795015 177 199 325653340 44 342 461...
output:
861519786 688215423 760926930 532860158
result:
ok 4 lines
Subtask #11:
score: 0
Wrong Answer
Test #73:
score: 0
Wrong Answer
time: 78ms
memory: 33304kb
input:
78545 146764 18353 73568 390778280 12956 64342 108778687 15074 61576 760673206 42118 71716 240356072 2787 39663 244001782 56627 68256 551718402 41708 74741 185084427 54908 55871 646459940 34896 59980 645111379 2554 54709 139732994 222 57068 172643582 34548 53342 121908641 17689 46437 342955316 42968...
output:
555397722 270502309 323462074 287354871 731191626
result:
wrong answer 2nd lines differ - expected: '503859531', found: '270502309'
Subtask #12:
score: 0
Wrong Answer
Test #85:
score: 0
Wrong Answer
time: 33ms
memory: 22084kb
input:
31126 49978 11370 29373 763709607 7784 30527 424491075 6825 18769 724126326 8225 28703 895476400 5674 25870 738364236 7240 26466 498917748 6427 27557 798811343 11304 27132 672101930 27476 31031 629664039 24050 29200 377006402 6716 18044 763174184 4099 4891 290207161 24287 26673 841170290 4755 16253 ...
output:
697457584 573424065 555191004 361053298 391468704 623748100 345184531 431618352 677679639 453461864 322180422 467921779 567987779 386552138 600275452 487944580 503124310 671769005 735875066 335954280 461728729 557590959 640594394 443302303 647260235 592189433 523526435 505945918 628063275 523816574 ...
result:
wrong answer 4th lines differ - expected: '543296805', found: '361053298'