Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
38038 | andy2025 | 【BJ】T1 | C++ | 通过 | 100 | 69 MS | 5944 KB | 2253 | 2025-06-10 16:08:25 |
#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][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 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; } while(hd <= tl) { int x = que[hd]; hd++; for(int i = 0;i <= n;i++) g[i][0] = f[x][i],g[i][1] = 0x3f3f3f3f; for(int i = 1;i <= scc[x].size();i++) { int now = scc[x][i - 1]; for(int j = n;j >= 1;j--) { g[j][0] = min(g[j][0],g[j - 1][0] + p[now].first); g[j][1] = min(g[j][1],g[j - 1][0] + p[now].second); g[j][1] = min(g[j][1],g[j - 1][1] + p[now].first); } } for(int i = 1;i <= n;i++) f[x][i] = min(g[i][1],f[x][i]); for(int i = 0;i < E[x].size();i++) { int y = E[x][i]; in[y]--; for(int j = 0;j <= n;j++) f[y][j] = min(f[y][j],f[x][j]); 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]); if(dp[i] != 0x3f3f3f3f) cout << dp[i] << "\n"; else break; } return 0; }