Ideas:
\ (Robot by the time a city = max (a city guard time to lift the robot arrival time here) \)
Code:
#include<bits/stdc++.h>
using namespace std;
struct E
{
int to, next, val;
};
E edge[70005];
int n, m, tot, first[3005], a[3005][3005], pro[3005], p[3005]; //pro:每个城市保护多少城市 p:每个城市受多少城市保护
void addedge(int x, int y, int z)
{
tot++;
edge[tot].to = y;
edge[tot].next = first[x];
edge[tot].val = z;
first[x] = tot;
}
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > heap;
bool vis[3005];
int d1[3005], d2[3005], d[3005]; //d1:到达时间 d2:可进入时间
void dijkstra()
{
memset(d, 63, sizeof(d));
memset(d1, 63, sizeof(d1));
heap.push(make_pair(0, 1));
d1[1] = 0;
d[1] = 0;
while(!heap.empty())
{
int now = heap.top().second;
heap.pop();
if(vis[now])
{
continue;
}
vis[now] = true;
for(int u = first[now]; u; u = edge[u].next)
{
int v = edge[u].to;
if(d[now] + edge[u].val < d1[v]) //到达时间
{
d1[v] = d[now] + edge[u].val;
d[v] = max(d1[v], d2[v]);
if(!p[v])
{
heap.push(make_pair(d[v], v));
}
}
}
for(int i = 1; i <= pro[now]; i++) //更新保护城市
{
int v = a[now][i];
p[v]--;
d2[v] = max(d2[v], d[now]);
d[v] = max(d1[v], d2[v]);
if(!p[v])
{
heap.push(make_pair(d[v], v));
}
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin >> n >> m;
for(int i = 1; i <= m; i++)
{
int u, v, w;
cin >> u >> v >> w;
addedge(u, v, w);
}
for(int i = 1; i <= n; i++)
{
cin >> p[i];
for(int j = 1, x; j <= p[i]; j++)
{
cin >> x;
pro[x]++;
a[x][pro[x]] = i;
}
}
dijkstra();
cout << d[n] << endl;
return 0;
}