QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#621983 | #8740. 科技树 | MiniLong | AC ✓ | 3ms | 16156kb | C++17 | 4.2kb | 2024-10-08 19:07:58 | 2024-10-08 19:07:59 |
Judging History
answer
#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define _rev(i, u) for(int i = head[u]; i; i = e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
using namespace std;
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
typedef long long ll;
typedef pair<int, int> PII;
namespace fastio{
#ifdef ONLINE_JUDGE
char ibuf[1 << 20],*p1 = ibuf, *p2 = ibuf;
#define get() p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++
#else
#define get() getchar()
#endif
template<typename T> inline void read(T &t){
T x = 0, f = 1;
char c = getchar();
while(!isdigit(c)){
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
t = x * f;
}
template<typename T, typename ... Args> inline void read(T &t, Args&... args){
read(t);
read(args...);
}
template<typename T> void write(T t){
if(t < 0) putchar('-'), t = -t;
if(t >= 10) write(t / 10);
putchar(t % 10 + '0');
}
template<typename T, typename ... Args> void write(T t, Args... args){
write(t), putchar(' '), write(args...);
}
template<typename T> void writeln(T t){
write(t);
puts("");
}
template<typename T> void writes(T t){
write(t), putchar(' ');
}
#undef get
};
using namespace fastio;
#define multitest() int T; read(T); _rep(tCase, 1, T)
namespace Calculation{
const ll mod = 998244353;
ll ksm(ll p, ll h){ll base = p % mod, res = 1; while(h){if(h & 1ll) res = res * base % mod; base = base * base % mod, h >>= 1ll;} return res;}
void dec(ll &x, ll y){x = ((x - y) % mod + mod) % mod;}
void add(ll &x, ll y){x = (x + y) % mod;}
void mul(ll &x, ll y){x = x * y % mod;}
ll sub(ll x, ll y){return ((x - y) % mod + mod) % mod;}
ll pls(ll x, ll y){return ((x + y) % mod + mod) % mod;}
ll mult(ll x, ll y){return x * y % mod;}
}
using namespace Calculation;
const int N = 1e6 + 5;
const ll inf = 0x3f3f3f3f3f3f3f3f;
ll n, m, p, q, f[N], h[N], g[N];
namespace Flow{
ll s, t;
ll ecnt = 1, head[N], cur[N];
struct edge{
ll v, w, nxt;
}e[N << 1];
void add(ll u, ll v, ll w){
e[++ecnt] = edge{v, w, head[u]}, head[u] = ecnt;
e[++ecnt] = edge{u, 0, head[v]}, head[v] = ecnt;
}
ll num[N];
bool bfs(ll s, ll t){
fill(num + s, num + t + 1, 0);
queue<int> q;
q.push(s), cur[s] = head[s], num[s] = 1;
while(q.size()){
int u = q.front(); q.pop();
_rev(i, u){
int v = e[i].v;
if(!num[v] && e[i].w){
num[v] = num[u] + 1;
cur[v] = head[v];
q.push(v);
}
}
}
return num[t];
}
ll dfs(ll u, ll in){
ll out = 0;
if(u == t) return in;
for(int i = cur[u]; i && in; i = e[i].nxt){
int v = e[i].v;
cur[u] = i;
if(e[i].w && num[v] == num[u] + 1){
int d = dfs(v, min(e[i].w, in));
e[i].w -= d, e[i ^ 1].w += d;
in -= d, out += d;
}
}
if(!out) num[u] = 0;
return out;
}
ll Dinic(){
ll Flow = 0;
while(bfs(s, t)) Flow += dfs(s, inf);
return Flow;
}
}
using namespace Flow;
int main(){
read(n, m, p, q);
ll ans = 0;
_rep(i, 1, n) read(f[i]);
_rep(i, 1, n) read(h[i]);
_rep(i, 1, m) read(g[i]), ans += g[i];
s = 0, t = 2 * n + m + 1;
_rep(i, 1, m) add(s, 2 * n + i, g[i]);
_rep(i, 1, p){
int u, v; read(u, v);
add(2 * n + v, u, inf);
}
_rep(i, 1, q){
int u, v; read(u, v);
add(v + n, u, inf);
}
_rep(i, 1, n){
if(f[i] > h[i]) add(i, t, h[i]), add(i, i + n, f[i] - h[i]);
else add(i, t, f[i]);
}
writeln(ans - Dinic());
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 16156kb
input:
20 20 106 60 764950822 789804781 628533600 142236215 12714072 356052061 484037108 723775690 717760704 273304732 835189828 150735512 484042916 196657060 269980077 335646130 133320719 575055485 591418974 518146158 692394693 437321875 355893295 101592648 10643103 164010005 81984062 263277829 327687399 ...
output:
6130508196
result:
ok single line: '6130508196'
Test #2:
score: 0
Accepted
time: 0ms
memory: 13912kb
input:
20 20 98 59 900318166 100963444 454887558 182056384 838991099 228151689 388669539 903200974 581910495 523980738 271472561 781845703 167769273 919184681 310810564 8323863 198507443 117413130 859117496 697623952 437997217 35166767 171668701 76868649 732637317 179470807 304173330 797231200 173236704 23...
output:
3318626889
result:
ok single line: '3318626889'
Test #3:
score: 0
Accepted
time: 3ms
memory: 15924kb
input:
20 20 125 67 673838881 274452922 991034907 322520796 703691851 643407286 177971463 322299303 723553547 704345361 588077868 76827875 85608101 718395798 921370273 571378998 698021927 534679330 981058457 865489485 158870047 246066216 556937497 32332315 699332445 604092901 95963749 99228323 668931244 41...
output:
2842802985
result:
ok single line: '2842802985'
Test #4:
score: 0
Accepted
time: 0ms
memory: 14080kb
input:
100 100 3083 1534 952855868 888519821 582781037 85552376 617034223 17000916 335144837 776123974 313285038 8999525 546235636 132912684 651399733 591099435 997904820 706665533 101971220 627411248 870706856 348619690 184933148 470075068 138669425 866811809 121044758 198311602 352855578 770908314 866931...
output:
24046219793
result:
ok single line: '24046219793'
Test #5:
score: 0
Accepted
time: 0ms
memory: 14080kb
input:
100 100 3188 1502 126930549 483061293 614262161 63892956 227473525 127778207 993584647 523197514 685276380 618659085 794761066 918733049 764219809 859984940 613462773 47619295 75865770 565843513 595300964 217219914 491067221 504850905 686723602 160299380 112880704 417484202 196193443 86798811 444010...
output:
26185530533
result:
ok single line: '26185530533'
Test #6:
score: 0
Accepted
time: 0ms
memory: 15916kb
input:
100 100 3145 1562 216301752 564758155 294427518 210122675 397917030 816320995 628519779 661385932 394837620 278347205 314932939 289361452 233775243 674682068 502777156 492786297 966422780 413934858 93597318 888515554 642799366 261256971 278532658 662091289 25711994 578741748 466001144 559518390 3503...
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 0ms
memory: 13816kb
input:
100 100 3058 1600 323289536 823133126 349609185 869110935 577733806 362200295 793237779 507148589 816233943 838933604 892077705 697746750 732931010 332168095 456903346 826976141 401413564 518901592 913940453 417246287 505254204 26881691 168549884 520352785 755620154 983227876 1207577 511112329 65627...
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 3ms
memory: 13912kb
input:
100 100 225 171 83843766 896783349 424997980 142381501 967194382 743947167 137702407 624558557 729591996 131063616 132603241 593524068 411226533 411273368 15268760 83871345 386459154 897645422 459722744 115364633 272553175 575915730 973345827 927617974 691970591 902337179 521473994 660750105 3360392...
output:
15313705050
result:
ok single line: '15313705050'
Test #9:
score: 0
Accepted
time: 0ms
memory: 15868kb
input:
100 100 231 173 77982424 221649167 650787795 700796828 302430609 37821091 136432185 926640700 251008871 889174152 745432485 122862540 2978557 823243620 576614701 842714027 468535138 759117708 45631161 724902212 533152559 542652299 86713704 40299423 204700064 293262128 585012066 495601888 205319100 1...
output:
12023891889
result:
ok single line: '12023891889'
Test #10:
score: 0
Accepted
time: 0ms
memory: 16088kb
input:
100 100 231 195 733981082 475617694 698360701 176482141 60965019 706820638 587315895 105635364 831969992 96639758 844360243 502015294 856936785 302948939 443411843 182449567 386934013 72906833 664107694 346086478 107870958 206977495 850489907 409077897 430137584 989111510 377889427 211563530 3748300...
output:
10155608396
result:
ok single line: '10155608396'
Test #11:
score: 0
Accepted
time: 3ms
memory: 13876kb
input:
100 100 234 158 10187322 198518227 513457265 568082556 287594242 219436763 477924372 851258283 183840042 405777291 777348914 75038012 117177255 755274510 747773358 141954581 352832141 822968575 638006636 817835393 590823130 274318268 902460247 983297664 705307708 71955830 539563402 640695695 7565342...
output:
10578444560
result:
ok single line: '10578444560'
Test #12:
score: 0
Accepted
time: 0ms
memory: 15912kb
input:
100 100 215 227 949521954 960570813 403143864 158420754 295877857 71489872 908095290 669211413 782279407 675613678 904791558 369739985 526865436 354684152 176000778 987126937 206269453 699219811 338272228 748054151 764231333 473019882 881202532 350176482 816737605 456761500 725761959 803178898 39735...
output:
8810864776
result:
ok single line: '8810864776'
Test #13:
score: 0
Accepted
time: 0ms
memory: 16152kb
input:
100 100 249 199 51159388 771299322 152235540 723508711 772384911 648776923 728292056 395341457 195956291 599046385 469353090 378349551 785101896 798913923 189858427 316868608 919041254 412897591 361300492 593214253 942961093 864463688 929026043 757481924 910124033 394744858 349405671 332617953 51204...
output:
8247554977
result:
ok single line: '8247554977'
Test #14:
score: 0
Accepted
time: 0ms
memory: 16148kb
input:
100 100 242 202 208946950 511513131 521967003 386563608 236763582 79811876 194082313 755867845 575970165 396616647 576991584 579748849 152825156 147479249 798585509 506535782 851542115 319232066 887774510 195705278 254732289 547559732 835003355 257278742 604602584 597894314 648997955 937399797 12687...
output:
12684051821
result:
ok single line: '12684051821'
Test #15:
score: 0
Accepted
time: 0ms
memory: 14108kb
input:
100 100 209 228 672250260 432721503 548423571 755228032 128721447 35286039 753164292 534601957 509428001 76856041 349402159 444240176 926074164 262955119 238524344 927943271 386354287 346568558 784162175 406305371 376520584 161139897 804725309 518418817 608677167 893922656 419381156 691896102 229139...
output:
11639121644
result:
ok single line: '11639121644'
Test #16:
score: 0
Accepted
time: 0ms
memory: 16088kb
input:
100 100 232 167 459651567 747032235 471420218 974591939 475733012 869250531 535300999 244104521 380345341 360652471 963837207 641858364 402186637 674049066 753567055 712525776 68017800 270226086 845312404 929312073 773592088 574287122 24717045 154762499 881540050 751094666 473272121 197472671 981165...
output:
9578091116
result:
ok single line: '9578091116'
Test #17:
score: 0
Accepted
time: 0ms
memory: 13872kb
input:
100 100 257 171 612020973 14369573 87310553 237118047 907105449 373378358 404382002 357423111 497384713 256402046 251889371 650562106 255761327 517984149 598323124 344652418 198177146 743615331 672555883 587496987 435017890 27970173 60124057 420959221 341276680 195991967 132258080 591906104 81706285...
output:
13912454897
result:
ok single line: '13912454897'
Test #18:
score: 0
Accepted
time: 3ms
memory: 15916kb
input:
100 100 830 589 305066670 75912563 452382225 728841043 705180394 140696085 362191600 622210589 942212432 959424784 250009056 204771766 895108553 956544119 330471434 621981150 115391392 950830534 481334082 682714054 24927374 35897060 816871314 355508470 824319856 413033328 52234218 643766398 59780435...
output:
2141701409
result:
ok single line: '2141701409'
Test #19:
score: 0
Accepted
time: 3ms
memory: 13876kb
input:
100 100 709 571 337928860 992192103 572512210 269951754 956798869 944071998 503560812 928530 144114007 943758468 867700289 281189098 511830328 177575484 643119327 553918028 576328031 905246036 464029359 355726551 626641380 703439576 290035961 884863728 116035012 307201269 193215021 956759684 2171363...
output:
2155312035
result:
ok single line: '2155312035'
Test #20:
score: 0
Accepted
time: 0ms
memory: 14108kb
input:
100 100 1006 612 769667242 55589621 365324166 804431940 961779057 658852885 576530037 350071802 665017864 578155900 226890569 525739405 176270920 139798899 456121058 794450691 467217357 105518463 443536444 511998374 637456392 576116888 192619157 471813168 645335352 831527968 791690081 16359328 69081...
output:
1716564154
result:
ok single line: '1716564154'
Test #21:
score: 0
Accepted
time: 0ms
memory: 13880kb
input:
100 100 1107 674 131202212 887844285 803567812 364334733 491424644 646359299 29250444 226425620 147757851 625503330 237618909 317483783 451438034 42430038 569760651 516008397 533962233 513215540 723819504 107187231 337590833 754783240 928520838 436133848 525703764 125163134 801430637 222742012 52896...
output:
2394756048
result:
ok single line: '2394756048'
Test #22:
score: 0
Accepted
time: 3ms
memory: 16120kb
input:
100 100 864 591 132459261 211892842 368466915 644343763 586139439 470568394 308173423 761412876 193641794 196524769 853939680 282967434 617198592 474415381 397063077 717781634 789251650 845969690 318821271 577637654 234173083 924253739 336822313 899346760 112658306 195917308 971691775 304601959 3209...
output:
1975019648
result:
ok single line: '1975019648'
Test #23:
score: 0
Accepted
time: 0ms
memory: 13876kb
input:
100 100 687 740 639583637 11440588 881814244 673729535 105398429 954826189 418400050 112708563 595657024 700301320 878936842 891136066 343784548 989186980 23387610 313739402 809257341 673993410 893324162 329851520 732877173 21916115 733720334 344165098 526471970 817502397 138555222 496246370 6918392...
output:
2619864347
result:
ok single line: '2619864347'
Test #24:
score: 0
Accepted
time: 0ms
memory: 15916kb
input:
100 100 336 273 918259170 505109887 747284575 262751870 648186415 429219536 609628468 637725133 506906325 348280272 234359857 544664650 398385872 202509342 721220303 63876535 767222446 195719338 745352411 445264051 754878261 855382273 398776760 815042780 956581660 939297536 868109630 391459041 87332...
output:
11518560652
result:
ok single line: '11518560652'
Test #25:
score: 0
Accepted
time: 3ms
memory: 13908kb
input:
100 100 332 283 297596380 456209855 211998028 581879283 472868547 683429924 548897233 258220421 616181744 431188053 483392903 421216246 487492055 337494458 993769151 567185719 24539934 567452607 845368657 440932546 259142300 779046171 106950791 137613601 339143200 907102938 457246107 27507617 635062...
output:
12977604276
result:
ok single line: '12977604276'
Test #26:
score: 0
Accepted
time: 0ms
memory: 14108kb
input:
100 100 358 255 521777040 667706025 55165992 107252278 263184633 802987573 981848759 860103331 167372839 494471353 161716393 355473615 254067151 997985799 691719401 308878047 257759245 696308368 784847733 550021838 23323614 764712465 998287775 633877122 857569463 598230547 519157128 650989391 122662...
output:
11647133639
result:
ok single line: '11647133639'
Test #27:
score: 0
Accepted
time: 0ms
memory: 15808kb
input:
100 100 424 241 534881134 526008093 175994119 464219393 382082790 213971514 219936611 699847707 601138083 406043323 247554778 784711030 899348970 404262352 325895611 642758722 335409870 445904920 502574854 118691208 106050547 624818226 682593526 568475050 546870933 650955006 393037298 576156217 6106...
output:
5601971654
result:
ok single line: '5601971654'
Test #28:
score: 0
Accepted
time: 3ms
memory: 13872kb
input:
100 100 312 322 789998125 486720531 473403775 222140855 295886144 808549336 207643526 892798135 265319039 184961002 738770155 368599771 432253068 791538262 387348472 522141054 574245682 266503201 776677659 103363155 210246622 233313453 564867211 512623909 823985940 380255857 224512901 511859775 5577...
output:
9796296927
result:
ok single line: '9796296927'
Test #29:
score: 0
Accepted
time: 0ms
memory: 15808kb
input:
100 100 380 286 440911448 764132365 242134194 636029297 335239195 210198624 182292853 317497547 454624560 430747617 743863347 428238347 590835284 687503434 493013297 623187416 410888888 368520274 450289444 303295162 434228950 652959668 279497956 557731650 715428943 322783413 544831108 527921996 7810...
output:
8262283212
result:
ok single line: '8262283212'
Test #30:
score: 0
Accepted
time: 0ms
memory: 13760kb
input:
100 100 320 284 825512100 532746600 281558552 281807239 509485285 720077275 129969647 895282098 733653850 469011694 382305909 572587935 499555624 642032751 867341930 685052950 722407928 457328691 410572087 860363371 106908272 518399687 879253496 319261825 298353867 550305937 207200465 108744092 1614...
output:
8832062177
result:
ok single line: '8832062177'
Test #31:
score: 0
Accepted
time: 0ms
memory: 15856kb
input:
100 100 387 297 408522 1 16285576 95 1 988 4877 1847 52 1 20725736 2 27 354 1597437 286401 68642047 7 4083695 26204 893 79312023 1 7 1733277 5521 3148769 63906087 14111 81790902 1 27 10 6 36 2 3823 1036 894 125 4923 381 26360950 11158480 724830 1 2 116808148 525 9244929 503 7 6316334 142026 90 17323...
output:
520214690
result:
ok single line: '520214690'
Test #32:
score: 0
Accepted
time: 0ms
memory: 16084kb
input:
100 100 378 252 244 126 6911937 3142 220748 5180121 2147 1455009 990401 84041 1 304 26 264637 238 1655746 578 72 3542187 4 225 69209 5 31409 158239 44 1 96426386 2953535 223 86532 154 1 1066 12541566 161325 1 10 6218 99947877 119 81341 135 374 3958 22810877 5792 91738 812230 49 669309 10080 7675901 ...
output:
815423446
result:
ok single line: '815423446'
Test #33:
score: 0
Accepted
time: 3ms
memory: 13772kb
input:
100 100 317 303 30 5458479 58 59586465 12159 4743383 16094 29464 3551970 9 397744 444 10 70518016 154991 1131625 20646 7569 33243729 71586 8544 1912 1 7552544 19 29 124 15404548 1 73867043 9833668 1699 158 11013686 982 593625 1120063 61 1999 1 12924583 971 486 5001972 217933 57 1238 5198001 759 5 1 ...
output:
669665597
result:
ok single line: '669665597'
Test #34:
score: 0
Accepted
time: 0ms
memory: 16152kb
input:
100 100 314 309 2027 905 9392 550 259 44000027 12324469 725308 1840295 267 219958 4 96360 73404230 872 74828 57 2 621829 7151016 78864791 2 374 132225 1580794 3517 550 396 64499579 1706061 238361898 126 36 219039457 141832 1 780 8 9514 5 2244937 192677853 223 1699 329 1 1773 31019890 1148 68933 31 5...
output:
898855902
result:
ok single line: '898855902'
Test #35:
score: 0
Accepted
time: 0ms
memory: 15924kb
input:
100 100 315 296 2 11 3504348 1208144 54 88 1 48 421575 8 3 595 990 70401 66460 464351 1 432 12613151 723 18872 460413 2191050 938280 208 1 8 3224341 5851749 1 1 30900172 29312165 31 178 467 1 2 94715341 4 5199738 3 505 6237213 919008 220 7279 1 12 477283 29638085 3539 52517212 24436 20584 1 3404 664...
output:
425116743
result:
ok single line: '425116743'
Test #36:
score: 0
Accepted
time: 0ms
memory: 15928kb
input:
100 100 407 233 2 25362 3 3 2577588 91805 3 5 157 6973056 78 471 29576458 8156572 549223 2 337890 1018 1 6 67379 3 155320 25643 268030 99115281 116458567 31285817 828 93352 8181 20 63 14 4 142672 1 19 225105 2360 84459 94907 2 205 56392739 17272 45678972 1377166 99 5633 1 13173 388 2915 2032659 662 ...
output:
780662166
result:
ok single line: '780662166'
Test #37:
score: 0
Accepted
time: 0ms
memory: 15916kb
input:
100 100 355 203 137903 527 418396 7479746 94964 17813 875246 19864 79956568 62006591 922870 214 142162 118191911 1398600 413 400696 29825 5060 2323136 45 592 1 197492546 7517 1 277541 105261404 17964323 1 492 7961945 19752867 82 928775 7926 5326778 61 6207 1000 292 1136 734189 1595623 28972470 32662...
output:
916371163
result:
ok single line: '916371163'
Test #38:
score: 0
Accepted
time: 0ms
memory: 13880kb
input:
100 100 316 251 178 6957 8917789 14 64 63 15734 338925 30746 22061 37180673 220546 133969923 97096 8894 6 330807 2 1556 2 14168946 1143 263535 364 3399 84232 87080 1399 1 149 138 1 21814 492 1124 1134401 2 1748 375 63209003 81998163 25860 8567 3156156 217432 2774657 2 5939 9 121 345 2569037 4394 2 4...
output:
609466906
result:
ok single line: '609466906'
Test #39:
score: 0
Accepted
time: 3ms
memory: 15860kb
input:
100 100 359 236 752008 9185231 28568 1787 15817852 12274 24041 1069 221039 40202423 2 8266 50 7880 8 13792771 52054451 2 3884515 555 3 94083 21045745 3820172 125 190868628 21856 42 216851 152047724 451 1 23453 343 3112 681 96887007 1 1 5 15234883 3420223 10918 738047 13252 1 13 1 125 863 53 11561843...
output:
640827127
result:
ok single line: '640827127'
Test #40:
score: 0
Accepted
time: 3ms
memory: 14084kb
input:
100 100 418 302 2 1 4339697 4021610 280344 476 1668839 1 84984 69 1244 592228 44 4 1 3101 78724194 2392 352120 33 7 28 3950 1385 380 6207 1 1507756 53 1 10898853 7 30 236859328 1243 14 2 24195696 7151420 1643 96 92654 34 22 9580963 13749 34 5988096 81416 2898 8606 22107 1 396 7226 41 7784 32 21603 2...
output:
1031139710
result:
ok single line: '1031139710'