GDOI # 348 continental hegemony [SDOI2010] shortest restrictions apply

There in a distant world of two countries: China is located in the western end of the country and in mainland eastern end Jason Chris countries. God the people of the two countries are two contradictory beliefs: Jason national symbol of darkness and destruction of faith God has · Brotherton, while Chris national symbol of faith and eternal light of God in Springfield · Brotherton. In January 8012 fantasy calendar, Jason country was officially declared · Brotherton is the only God of their faith, while at the beginning of the persecution Chris Anglican faith · Spring Jason country of Brotherton. Fantasy calendar 8012 on March 2, Chris Anglican located in the eastern town of Jason oracle country town uprising. Fantasy calendar 8012 on March 7, Oracle town uprising was Jason national army repression brutal means. Fantasy calendar 8012 on March 8, Chris Jason States declared war on the country. By the hundreds of thousands of army corps consisting of Chris to open the border, and Jason Legion confrontation. In April 8012 fantasy calendar, Chris Army Corps Jason break into the defense of the town of Oracle, Chris Anglican surviving town liberated. Then the war into a stalemate, protracted. Fierce fighting, a time hail of bullets, smoke, times of hardship. Fantasy calendar 8012 on May 12 night, Springfield · Brotherton lowered oracle: "Trust me, earn eternal life." Chris Legion morale greatly increased. As coach Chris Corps, you decide to use this opportunity to launch a surprise attack, beat Jason countries.

Description [title]

Jason state-N cities connected by the M-way road. Oracle town is the capital city and a country's urban Jason N. You only need to destroy the temple is located has great Brotherton · Jason nation's capital, the country's Jason faith, everything will fall apart as well as the army, wiped out. In order to minimize the consumption of one's own, you decide to use the robot blew accomplish this task. The only difficulty is that part of the city enchantment Jason countries have to protect, not destroy the enchantment will not be able to enter the city. And each city ward is maintained by the distribution in other cities some enchantment generator, if you want to enter a city, you have to destroy all the enchantment generator to maintain the enchantment of this city. Now you have an infinite number of robot blew, a city once entered, the robot can instantly blew detonated, destroying a target (enchantment generator, or Jason National Pantheon), of course, the robot itself will be destroyed together. You need to know: the destruction of Jason minimum time required for the country.

[Input Format]

The first line of two positive integers N, M. Next M rows, each row of three positive integers  U I V I W I , expressed from a city U I city V I a one-way road, blew this way required by the robot W I time.

After N lines, each describing a city. The first is a positive integer  L I , the number of sustain this circle city Ward generator used.

After L I cities numbers between 1 ~ N, it represents the position of each ward generator. If L I = 0 , it indicates that the city is not protected junction boundary.

Ensure L . 1 = 0 .

[Output format]

Only contains a positive integer, beat Jason minimum time required for the country.

 

This question is very simple, dij + topology.

FIG build two, the original is a view there is a topology diagram Ward

Open three arrays dis, time, ans. dis [i], time [i], ans [i] i to represent the shortest, the fastest of all the enchantment i be destroyed time and i can blow up the fastest time (that is, the final answer)

显然ans[i] = max(dis[i], time[i])。

In addition, we also need an array to record the number of nodes in enchantment, like the degree of the same.

When two running dij FIG run, a picture, a topology map. Note that only the degree of (in) is 0 to the queue.

#include <bits/stdc++.h>
using namespace std;
const int MAX = 10000000;
struct node{
    int pre, to, val;
}e1[MAX], e2[MAX];
int h1[MAX], h2[MAX], tot1, tot2;
int n, m, in[MAX]; int read() { int ret = 0, f = 1; char ch = getchar(); while ('0' > ch || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while ('0' <= ch && ch <= '9') { ret = ret * 10 + ch - '0'; ch = getchar(); } return ret * f; } void write(int x) { if (x < 0) { putchar('-'); x = -x; } if (x >= 10) write(x / 10); putchar(x % 10 + '0'); } void push_e1(int u, int v, int t) { e1[++tot1] = node{h1[u], v, t}; h1[u] = tot1; } void push_e2(int u, int v) { e2[++tot2] = node{h2[u], v, 0}; h2[u] = tot2; } priority_queue<pair<int, int> > q; bool vis[MAX]; int dis[MAX], ans[MAX], _time[MAX]; void dijkstra() { memset(dis, 0x3f, sizeof(dis)); dis[1] = 0; ans[1] = 0; _time[1] = 0; q.push(make_pair(0, 1)); while (!q.empty()) { int x = q.top().second; q.pop(); if (vis[x]) continue; vis[x] = 1; for (int i = h1[x]; i; i = e1[i].pre) { int y = e1[i].to, z = e1[i].val; if (dis[y] > ans[x] + z) { dis[y] = ans[x] + z; if (!in[y]) { ans[y] = max(dis[y], _time[y]); q.push(make_pair(-ans[y], y)); } } } for (int i = h2[x]; i; i = e2[i].pre) { int y = e2[i].to; if (in[y]) { in[y]--; _time[y] = max(_time[y], ans[x]); if (!in[y]) { ans[y] = max(dis[y], _time[y]); q.push(make_pair(-ans[y], y)); } } } } } int main() { n = read(), m = read(); for (int i = 1, u, v, t; i <= m; i++) { u = read(), v = read(), t = read(); push_e1(u, v, t); } for (int i = 1; i <= n; i++) { in[i] = read(); for (int j = 1, x; j <= in[i]; j++) { x = read(); push_e2(x, i); } } dijkstra(); write(ans[n]); putchar('\n'); }

· Springfield Brotherton: I now have an unlimited number of robot blew, hey hey hey ......

· Once Brotherton: Amount (⊙o⊙) ...

 

Guess you like

Origin www.cnblogs.com/zcr-blog/p/11330117.html