题面
https://www.luogu.org/problem/P2446
题解
// luogu-judger-enable-o2 #include<cstdio> #include<iostream> #include<cstring> #include<vector> #include<queue> #define LL long long #define ri register int #define N 3050 using namespace std; int n,m; vector<int> to[N],len[N]; vector<int> fa[N]; LL dis[N],d[N]; bool vis[N]; int cnt[N],tot[N]; void add_edge(int z,int y,int x) { to[z].push_back(y); len[z].push_back(x); } struct node { int x; LL d; bool operator < (const node &rhs) const { return d>rhs.d; } }; priority_queue<node> q; LL dij() { memset(dis,0x3f,sizeof(dis)); dis[1]=0; q.push((node){1,0}); while (!q.empty()) { int x=q.top().x; q.pop(); if (vis[x]) continue; vis[x]=1; for (ri i=0;i<fa[x].size();i++) { dis[fa[x][i]]=max(dis[x],dis[fa[x][i]]); cnt[fa[x][i]]++; if (cnt[fa[x][i]]==tot[fa[x][i]]) { q.push((node){fa[x][i],dis[fa[x][i]]}); } } for (ri i=0;i<to[x].size();i++) { int y=to[x][i]; if (dis[y]>dis[x]+len[x][i]) { dis[y]=dis[x]+len[x][i]; if (cnt[y]==tot[y]) q.push((node){y,dis[y]}); } } } return dis[n]; } int main() { int a,b,c; scanf("%d %d",&n,&m); for (ri i=1;i<=m;i++) { scanf("%d %d %d",&a,&b,&c); add_edge(a,b,c); } for (ri i=1;i<=n;i++) { scanf("%d",&tot[i]); for (ri j=1;j<=tot[i];j++) { scanf("%d",&b); fa[b].push_back(i); } } cout<<dij()<<endl; }