QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#427524 | #8743. 转化 | PorNPtree# | WA | 8ms | 4668kb | C++17 | 4.0kb | 2024-06-01 13:37:48 | 2024-06-01 13:37:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 105, M = 1005;
int c[N], du[N];
vector<int> G[N];
vector< vector<int> > tG[N];
__int128 res[N], bc[N], Rc[N];
void dfs(int x) {
if (res[x]) return;
res[x] = -1;
for (auto v : G[x]) dfs(v);
}
void output(__int128 x) {
if (!x) return;
output(x / 10); putchar(x % 10 + '0');
}
int dfn[N], low[N], inS[N], bcc[N];
vector<int> wh[N], nG[N], rG[N];
stack<int> S;
void Tarjan(int x) {
dfn[x] = low[x] = ++dfn[0];
S.push(x); inS[x] = 1;
for (auto v : G[x]) {
if (!dfn[v]) {
Tarjan(v);
low[x] = min(low[x], low[v]);
} else if (inS[v]) {
low[x] = min(low[x], dfn[v]);
}
}
if (dfn[x] == low[x]) {
++bcc[0];
int v;
do {
v = S.top(); S.pop();
inS[v] = 0; bcc[v] = bcc[0];
wh[bcc[0]].push_back(v);
} while (v != x);
}
}
void dfsdfs(int x) {
if (bc[x] == -2) return;
bc[x] = -2;
for (auto v : nG[x]) {
dfsdfs(v);
}
}
__int128 xishu[N];
signed main() {
int n, m; scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%d", &c[i]);
}
for (int i = 1; i <= m; ++i) {
int a, k; scanf("%d%d", &a, &k);
tG[a].push_back(vector<int>{});
while (k--) {
int x; scanf("%d", &x);
tG[a].back().push_back(x);
G[a].push_back(x);
++du[x];
}
}
for (int i = 1; i <= n; ++i) {
if (c[i]) dfs(i);
}
for (int i = 1; i <= n; ++i) {
if (!dfn[i]) {
Tarjan(i);
}
Rc[bcc[i]] += c[i];
}
for (int i = 1; i <= n; ++i) {
for (auto v : G[i]) {
if (bcc[i] != bcc[v]) {
nG[bcc[i]].push_back(bcc[v]);
}
}
}
for (int i = 1; i <= bcc[0]; ++i) {
sort(nG[i].begin(), nG[i].end());
nG[i].erase(unique(nG[i].begin(), nG[i].end()), nG[i].end());
for (auto x : nG[i]) {
rG[x].push_back(i);
}
}
for (int i = 1; i <= bcc[0]; ++i) if (res[i]) {
int C = 0;
for (auto v : wh[i]) {
for (auto w : G[v]) {
if (bcc[w] == i) {
++C;
}
}
}
if (C >= wh[i].size()) {
for (auto iv : nG[i]) {
dfsdfs(iv);
}
}
if (C > wh[i].size()) {
int flg = 0;
for (auto v : wh[i]) {
for (auto z : tG[v]) {
int s = 0;
for (auto zz : z) {
s += (bcc[zz] == i);
}
flg |= (s >= 2);
}
}
if (flg) dfsdfs(i);
}
}
for (int i = 1; i <= n; ++i) {
if (res[i] == -1 && bc[bcc[i]] != -2) {
bc[bcc[i]] = -1;
}
}
for (int i = 1; i <= bcc[0]; ++i) {
if (bc[i] != -1) {
continue;
}
for (int j = 1; j <= bcc[0]; ++j) {
xishu[j] = 0;
}
xishu[i] = 1;
for (int j = 1; j <= bcc[0]; ++j) {
if (j != i && wh[j].size() == 1) {
int pos = wh[j][0];
for (int k = 0; k < tG[pos].size(); ++k) {
__int128 s = 0;
for (int l = 0; l < tG[pos][k].size(); ++l) {
s += xishu[bcc[tG[pos][k][l]]];
}
xishu[j] = max(xishu[j], s);
}
}
}
bc[i] = 0;
for (int j = 1; j <= bcc[0]; ++j) {
bc[i] += xishu[j] * Rc[j];
}
}
for (int i = 1; i <= n; ++i) {
if (res[i] == 0) puts("0");
else if (res[i] == -2 || bc[bcc[i]] == -2) puts("infinity");
else output(bc[bcc[i]]), putchar('\n');
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 4668kb
input:
100 1000 327 833 558 253 722 710 811 779 789 919 750 288 611 674 670 264 815 701 304 615 9 943 713 633 392 706 687 847 78 999 368 55 913 61 686 512 696 0 695 285 485 877 533 54 621 925 339 319 597 536 285 701 186 933 234 360 284 546 545 185 112 735 147 851 824 512 695 734 237 381 777 449 880 675 614...
output:
2155053232761438 74047065246801194391656046 965 2426374234007181537825780832913 1213187117003590768912890416691 18077896788769822849609 282467137324528482092 144623174310158582796217 2007265 67345413524067 256902392 8220875576 564934274649056963984 34480851724185745 9478024351590552882131956367 1284...
result:
ok 100 lines
Test #2:
score: 0
Accepted
time: 8ms
memory: 4436kb
input:
100 1000 419 67 836 765 105 801 89 109 677 745 664 148 719 22 617 422 362 483 748 435 244 922 129 307 166 80 740 851 422 364 757 277 322 626 671 395 21 875 774 645 727 336 958 164 105 109 371 841 276 625 154 234 632 999 597 527 793 536 927 511 169 27 289 924 982 178 859 721 430 988 603 900 917 850 5...
output:
120220501669479055473315 15027562708684881933938 1834419275962510223 895712537091260 109339909112 1668501 13667488579 208275 16135722593097685769228065065040 984846349676372422438236478 437359637273 223928134272617 874719274601 114651204747656549 258171561489562972307649041041141 834061 27334977431 ...
result:
ok 100 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 3728kb
input:
100 40 277 790 179 390 145 440 959 311 334 364 791 756 22 0 518 476 992 10 515 830 316 92 38 716 42 51 310 16 101 324 634 644 793 890 793 433 828 756 996 910 55 993 690 357 176 428 415 779 792 13 565 55 386 363 855 662 284 564 887 894 738 212 630 866 91 937 483 93 479 62 101 797 250 847 872 105 639 ...
output:
infinity 790 infinity infinity infinity infinity infinity infinity 334 infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity 38 infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity i...
result:
ok 100 lines
Test #4:
score: 0
Accepted
time: 1ms
memory: 3728kb
input:
100 40 338 5 608 722 335 92 306 237 534 205 6 503 192 304 433 960 828 352 578 658 230 413 617 603 407 208 702 31 685 443 209 848 700 453 566 971 485 13 881 213 885 849 798 979 50 866 738 126 958 494 271 754 951 739 937 470 356 374 317 903 197 762 48 105 199 104 921 974 308 609 950 130 83 188 304 526...
output:
infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity 6 infinity infinity 1225 infinity infinity infinity infinity 578 infinity infinity infinity infinity infinity infinity infinity infinity 31 infinity infinity infinity infinity 700 infinity infinity infinity inf...
result:
ok 100 lines
Test #5:
score: 0
Accepted
time: 1ms
memory: 3700kb
input:
100 40 818 149 271 956 869 50 786 402 223 295 451 708 548 973 335 51 871 118 906 911 694 175 67 700 196 5 615 100 868 978 401 348 484 974 412 213 144 110 36 620 708 657 583 435 791 954 947 646 893 790 947 699 988 314 917 797 437 616 886 769 6 179 831 781 265 206 348 539 267 529 271 695 355 556 194 3...
output:
infinity infinity infinity 956 infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity 903 infinity infinity infinity infinity infinity infinity infinity 836 infinity infinity infinity infinity ...
result:
ok 100 lines
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 3800kb
input:
100 40 304 57 357 802 923 636 126 589 811 687 954 327 650 414 530 546 27 361 221 693 751 277 370 542 555 308 810 898 602 576 933 52 335 196 620 913 645 154 151 277 735 875 921 908 488 945 586 738 697 202 479 930 216 581 949 525 168 422 151 964 293 172 171 950 872 2 64 602 371 32 72 728 773 723 157 3...
output:
infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity 327 infinity infinity infinity infinity 27 infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity 898 infinity infinity infinity infinity infinity infinity infinity i...
result:
wrong answer 80th lines differ - expected: '911', found: 'infinity'