QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#427406 | #8743. 转化 | PorNPtree# | WA | 8ms | 4696kb | C++17 | 3.6kb | 2024-06-01 13:14:01 | 2024-06-01 13:14:02 |
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 (res[x] == -2) return;
res[x] = -2;
for (auto v : G[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) {
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()) {
res[i] = -2;
}
}
for (int i = 1; i <= n; ++i) {
if (res[i] != -1) {
bc[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 (bc[j] != -1 && 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);
}
}
}
for (int j = 1; j <= bcc[0]; ++j) {
bc[i] += xishu[j] * Rc[j];
}
}
for (int i = 1; i <= n; ++i) {
if (res[i] == -2) puts("infinity");
else if (res[i] == 0) puts("0");
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: 8ms
memory: 4696kb
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: 4ms
memory: 4440kb
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: -100
Wrong Answer
time: 1ms
memory: 4032kb
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 infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity infinity...
result:
wrong answer 9th lines differ - expected: '334', found: 'infinity'