Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
38036 | andy2025 | 【BJ】T1 | C++ | 运行超时 | 50 | 2000 MS | 13888 KB | 2582 | 2025-06-10 15:54:57 |
#include <bits/stdc++.h> using namespace std; const int N = 1010,M = 1000010; int n,ins[N],stk[N],dfn[N],low[N],bel[N],top,cnt,tot; int g[N][N][2],f[N][N],in[N],que[N],hd = 1,tl,dp[N]; pair <int,int> p[N]; vector <int> G[N],scc[N],E[N]; void Tarjan(int x) { stk[++top] = x; ins[x] = 1; dfn[x] = low[x] = ++cnt; for(int i = 0;i < G[x].size();i++) { int y = G[x][i]; 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]) { tot++; while(top) { int t = stk[top]; top--; ins[t] = 0; bel[t] = tot; scc[tot].push_back(t); if(t == x) break; } } } int main() { /*freopen("goodeat.in","r",stdin); freopen("goodeat.out","w",stdout);*/ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; memset(dp,0x3f,sizeof(dp)); for(int i = 1,ct;i <= n;i++) { cin >> p[i].first >> p[i].second >> ct; for(int j = 1,x;j <= ct;j++) { cin >> x; G[i].push_back(x); } } for(int i = 1;i <= n;i++) if(!dfn[i]) Tarjan(i); memset(g,0x3f,sizeof(g)); memset(f,0x3f,sizeof(f)); for(int i = 1;i <= tot;i++) { g[i][0][0] = 0; for(int j = 1;j <= scc[i].size();j++) { for(int k = scc[i].size();k >= 1;k--) { int x = scc[i][j - 1]; g[i][k][0] = min(g[i][k][0],g[i][k - 1][0] + p[x].first); g[i][k][1] = min(g[i][k][1],g[i][k - 1][1] + p[x].first); g[i][k][1] = min(g[i][k][1],g[i][k - 1][0] + p[x].second); } } } for(int x = 1;x <= n;x++) { for(int i = 0;i < G[x].size();i++) { int y = G[x][i]; if(bel[x] == bel[y]) continue; E[bel[x]].push_back(bel[y]); in[bel[y]]++; } } for(int i = 1;i <= tot;i++) { if(!in[i]) que[++tl] = i; f[i][0] = 0; for(int j = 1;j <= scc[i].size();j++) f[i][j] = g[i][j][1]; } while(hd <= tl) { int x = que[hd]; hd++; for(int i = 0;i < E[x].size();i++) { int y = E[x][i]; in[y]--; for(int k = n;k >= 0;k--) { f[y][k] = min(f[y][k],f[x][k]); for(int j = 0;j < k;j++) f[y][k] = min(f[y][k],f[x][j] + g[y][k - j][1]); } if(!in[y]) que[++tl] = y; } } for(int i = 1;i <= n;i++) { for(int j = 1;j <= tot;j++) { dp[i] = min(dp[i],f[j][i]); //cout << j << " " << i << " " << f[j][i] << "\n"; } if(dp[i] != 0x3f3f3f3f) cout << dp[i] << "\n"; else break; } return 0; }