QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#430419 | #8743. 转化 | ANewZhiyangfan# | WA | 4ms | 4984kb | C++14 | 3.4kb | 2024-06-03 19:59:16 | 2024-06-03 19:59:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
template <typename T>inline void read(T &x)
{
x=0;char c=getchar();bool f=0;
for(;c<'0'||c>'9';c=getchar())f|=(c=='-');
for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+(c-'0');
x=(f?-x:x);
}
const int N = 1005;
const int M = 1005;
vector<int> transport[N];
int K[M];
vector<int> seq[M];
vector<int> G[N];
int dfn[N],low[N],ins[N],num=0;
vector<int> scc[N];
stack<int> st;
int bel[N],cnt=0;
int n,m;
void tarjan(int x)
{
dfn[x]=low[x]=++num;
st.push(x);
ins[x]=1;
for(int y:G[x])
{
if(!dfn[y])
{
tarjan(y);
low[x]=min(low[x],low[y]);
}
else if(ins[y])
{
low[x]=min(low[x],dfn[y]);
}
}
if(dfn[x]==low[x])
{
cnt++;
int y;
do
{
y=st.top();
st.pop();
ins[y]=0;
bel[y]=cnt;
scc[cnt].push_back(y);
}while(x!=y);
}
}
int tim[N],ord[N],pos[N],tot=0;
int deg[N];
vector<int> T[N];
typedef long long LL;
LL f[N][N],S[N],C[N];
int type[N];
LL Ans[N];
void solve(int x)
{
f[x][x]=1;
for(int i=pos[x]-1;i>=1;i--)
{
int u=ord[i];
for(int y:scc[u])
for(int j:transport[y])
if(type[j]==4)
{
LL sum=0;
for(int z:seq[j])
sum+=f[bel[z]][x];
f[u][x]=max(f[u][x],sum);
}
}
for(int i=1;i<=tot;i++)
Ans[x]+=f[i][x]*S[i];
}
int fro[N];
bool inf[N];
int main()
{
read(n);read(m);
for(int i=1;i<=n;i++)read(C[i]);
for(int i=1;i<=m;i++)
{
int x;
read(x);
fro[i]=x;
read(K[i]);
for(int j=1;j<=K[i];j++)
{
int y;
read(y);
seq[i].push_back(y);
G[x].push_back(y);
}
transport[x].push_back(i);
}
queue<int> q;
for(int i=1;i<=n;i++)
if(!dfn[i])tarjan(i);
for(int i=1;i<=n;i++)S[bel[i]]+=C[i];
for(int x=1;x<=n;x++)
for(int y:G[x])
{
if(bel[x]!=bel[y])
{
T[bel[x]].push_back(bel[y]);
deg[bel[y]]++;
}
}
for(int i=1;i<=m;i++)
{
bool flag=1,flag2=0;
int s=fro[i];
for(int y:seq[i])flag&=(bel[s]==bel[y]),flag2|=(bel[s]==bel[y]);
if(flag&&K[i]==1)type[i]=1;
else if(flag)type[i]=2;
else if(flag2)type[i]=3;
else type[i]=4;
}
for(int i=1;i<=cnt;i++)if(!deg[i])q.push(i);
while(!q.empty())
{
int x=q.front();
ord[++tot]=x;
pos[x]=tot;
q.pop();
for(int y:T[x])
{
deg[y]--;
if(!deg[y])q.push(y);
}
}
for(int x=1;x<=cnt;x++)
{
solve(x);
}
for(int u=1;u<=tot;u++)
if(Ans[u]>0)
{
for(int y:scc[u])
for(int i:transport[y])
if(type[i]==2)inf[u]=1;
else if(type[i]==3)
{
for(int z:seq[i])
if(bel[z]!=u)inf[bel[z]]=1;
}
}
for(int i=1;i<=tot;i++)if(inf[i])q.push(i);
while(!q.empty())
{
int x=q.front();
q.pop();
for(int y:T[x])
{
if(!inf[y])
{
inf[y]=1;
q.push(y);
}
}
}
for(int i=1;i<=n;i++)
{
if(inf[bel[i]])printf("infinity\n");
else printf("%lld\n",Ans[bel[i]]);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 4984kb
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 7910543595860854256 965 394795221151032631 -8114186283230007088 4408176815695727726 5765976218885207852 5667728368714325930 2007265 67345413524067 256902392 8220875576 -6914791635939136112 34480851724185745 2179816164250259075 128450953 16836353381018 526136043133 294504146439813638...
result:
wrong answer 2nd lines differ - expected: '74047065246801194391656046', found: '7910543595860854256'