BZOJ1922 [SDOI2010] 大陆争霸

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1922 题面废话真多我就删掉一部分……

Description

杰森国有 N 个城市,由 M条单向道路连接。神谕镇是城市 1而杰森国的首都是城市 N。你只需摧毁位于杰森国首都的曾·布拉泽大神殿,杰森国的信仰,军队还有一切就都会土崩瓦解,灰飞烟灭。 为了尽量减小己方的消耗,你决定使用自爆机器人完成这一任务。唯一的困 难是,杰森国的一部分城市有结界保护,不破坏掉结界就无法进入城市。而每个 城市的结界都是由分布在其他城市中的一些结界发生器维持的,如果想进入某个城市,你就必须破坏掉维持这个城市结界的所有结界发生器。 现在你有无限多的自爆机器人,一旦进入了某个城市,自爆机器人可以瞬间引爆,破坏一个目标(结界发生器,或是杰森国大神殿),当然机器人本身也会一起被破坏。你需要知道:摧毁杰森国所需的最短时间。

Input

第一行两个正整数 N, M。 接下来 M行,每行三个正整数 ui, vi, wi,表示有一条从城市ui到城市 vi的单 向道路,自爆机器人通过这条道路需要 wi的时间。 之后 N 行,每行描述一个城市。首先是一个正整数 li,维持这个城市结界所 使用的结界发生器数目。之后li个1~N 之间的城市编号,表示每个结界发生器的 位置。如果 Li = 0,则说明该城市没有结界保护,保证L1 = 0 。

Output

仅包含一个正整数 ,击败杰森国所需的最短时间。
 
小号跑得比大号还快挤进了前十233333
两个距离数组d1和d2,分别记录实际进入某一个点的时间和到达时间
每次在堆中取出一个点,遍历其出边,将其保护的点的“保护度”减1,并更新出边指向的点的实际进入时间
如果“保护度”为0即将出边指向的点入堆
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <cstring>
 5 #include <queue>
 6 #define rep(i,l,r) for(int i=l; i<=r; i++)
 7 #define clr(x,y) memset(x,y,sizeof(x))
 8 #define travel(x) for(Edge *p=last[x]; p; p=p->pre)
 9 using namespace std;
10 const int INF = 0x3f3f3f3f;
11 const int maxn = 3010;
12 int n,m,x,y,z,d1[maxn],d2[maxn],protect[maxn];
13 bool vis[maxn];
14 struct Edge{
15     Edge *pre;
16     int to,cost;
17 }edge[100010];
18 Edge *last[maxn],*pt;
19 struct node{
20     int x,d;
21     node(int _x,int _d) : x(_x), d(_d){}
22     inline bool operator < (const node &_Tp) const {
23         return d > _Tp.d;
24     }
25 };
26 priority_queue <node> q;
27 inline int read(){
28     int ans = 0, f = 1; char c = getchar();
29     while (!isdigit(c)){
30         if (c == '-') f = -1; c = getchar();
31     }
32     while (isdigit(c)){
33         ans = ans * 10 + c - '0'; c = getchar();
34     }
35     return ans * f;
36 }
37 inline void addedge(int x,int y,int z){
38     pt->pre = last[x]; pt->to = y; pt->cost = z; last[x] = pt++;
39 }
40 void init(){
41     n = read(); m = read(); clr(last,0); pt = edge;
42     rep(i,1,m){
43         x = read(); y = read(); z = read();
44         addedge(x,y,z);
45     }
46     rep(i,1,n){
47         x = read(); protect[i] = x;
48         rep(j,1,x) y = read(), addedge(y,i,0);
49     }
50 }
51 void dijkstra(){
52     clr(d1,INF); d1[1] = 0; q.push(node(1,0)); clr(vis,0);
53     while (!q.empty()){
54         node now = q.top(); q.pop();
55         if (vis[now.x]) continue; vis[now.x] = 1;
56         travel(now.x){
57             if (!p->cost){
58                 protect[p->to]--; d2[p->to] = max(d2[p->to],d1[now.x]);
59                 d1[p->to] = max(d1[p->to],d2[p->to]);
60                 if (!protect[p->to]) q.push(node(p->to,d1[p->to]));
61             }
62             else{
63                 if (d1[p->to] > d1[now.x] + p->cost){
64                     d1[p->to] = d1[now.x] + p->cost;
65                     if (!protect[p->to]) q.push(node(p->to,d1[p->to]));
66                 }
67             }
68         }
69     }
70     printf("%d\n",d1[n]);
71 }
72 int main(){
73     init();
74     dijkstra();
75     return 0;
76 }
View Code

 

posted on 2015-12-12 17:21  ACMICPC  阅读(170)  评论(0编辑  收藏  举报

导航