zzuoj 10405: I.Earthquake 【最小割】

10405: I.Earthquake

Time Limit: 2 Sec  Memory Limit: 128 MB
Submit: 19  Solved: 4
[ Submit][ Status][ Web Board]

Description

Wenchuan has had an earthquake that has struck a town.The earthquake has damaged some of the villages so that they are unpassable. Remarkably, none of  paths  was damaged.

 

As usual, the town is modeled as a set of  P (1 <= P <= 3,000)  villages conveniently numbered 1…P which are connected by a set of C (1 <= C <= 20,000) non-directional paths conveniently numbered 1...C.  path  i  connectsvillage Ai and Bi. paths might connect Ai to itself or perhaps might connect twovillages more than once.  The town government is located in village 1.

 

A total of  N (1 <= N <= P)  villages sequentially contacts  the town government via moobile phone with an integer message Vj (2 <= Vj <= P) that indicates that village Vj is undamaged , but the villagers is unable to return to the town governmentfrom village Vj , because they could not find a path that does not go through damaged  villages.

 

After all the villages report  in,  determine the minimum number of  villages that are damaged.

Input

The first line of input gives a single integer, 1 ≤ T ≤ 10, the number of test cases. Then follow, for each test case

* Line 1:             Three space-separated integers: P, C, and N

* Lines 2…C+1:       Line i+1 describes path i with two integers: Ai  and Bi

* Lines C+2…C+N+1:  Line C+1+j contains a single integer: Vj

Output

Output for each test case , a single line with a integer  K ,the minimum number of damaged  villages.

Sample Input

1
5 5 2
1 2
2 3
3 5
2 4
5
45

Sample Output

1


题意:有n个村庄和m条路,当某个村庄被破坏时则不能通过该村庄(道路不会被破坏)。现在知道有p个村庄没有被破坏,但不能连通村庄1。问你该情况下,最小有多少个村庄被破坏。


思路:很裸的最小割。

建图:无向边容量为INF,表示不能阻断。源点S到给定的p个村庄建有向边,容量为INF,表示不能阻断。

给定的p个村庄拆为左右点,容量为INF,表示不能被破坏。其它村庄拆为左点和右点,容量为1。汇点就为1的左点。


AC代码:


#include <iostream> 
#include <cstdio> 
#include <cstring> 
#include <cmath> 
#include <algorithm> 
#include <map> 
#include <string> 
#include <vector> 
#include <queue> 
#include <stack> 
#define CLR(a, b) memset(a, (b), sizeof(a)) 
using namespace std; 
typedef long long LL; 
const int MOD = 1e9+7; 
const int MAXN = 6000+10; 
const int MAXM = 200000; 
const int INF = 0x3f3f3f3f; 
void add(LL &x, LL y) {x += y; x %= MOD;} 
struct Edge{ 
    int from, to, cap, flow, next; 
}; 
Edge edge[MAXM]; 
int head[MAXN], edgenum; 
void init() {CLR(head, -1); edgenum = 0;} 
void addEdge(int u, int v, int w) 
{ 
    Edge E = {u, v, w, 0, head[u]}; 
    edge[edgenum] = E; 
    head[u] = edgenum++; 
    Edge E1 = {v, u, 0, 0, head[v]}; 
    edge[edgenum] = E1; 
    head[v] = edgenum++; 
} 
bool vis[MAXN]; 
int dist[MAXN], cur[MAXN]; 
bool Bfs(int s, int t) 
{ 
    queue<int> Q; Q.push(s); 
    CLR(vis, false); CLR(dist, -1); 
    vis[s] = true; dist[0] = 0; 
    while(!Q.empty()) 
    { 
        int u = Q.front(); Q.pop(); 
        for(int i = head[u]; i != -1; i = edge[i].next) 
        { 
            Edge E = edge[i]; 
            if(!vis[E.to] && E.cap > E.flow) 
            { 
                dist[E.to] = dist[u] + 1; 
                if(E.to == t) return true; 
                vis[E.to] = true; 
                Q.push(E.to); 
            } 
        } 
    } 
    return false; 
} 
int DFS(int x, int a, int t) 
{ 
    if(x == t || a == 0) return a; 
    int flow = 0, f; 
    for(int &i = cur[x]; i != -1; i = edge[i].next) 
    { 
        Edge &E = edge[i]; 
        if(dist[E.to] == dist[x] + 1 && (f = DFS(E.to, min(E.cap-E.flow, a), t)) > 0) 
        { 
            edge[i].flow += f; 
            edge[i^1].flow -= f; 
            flow += f; 
            a -= f; 
            if(a == 0) break; 
        } 
    } 
    return flow; 
} 
int Maxflow(int s, int t) 
{ 
    int flow = 0; 
    while(Bfs(s, t)) 
    { 
        memcpy(cur, head, sizeof(head)); 
        flow += DFS(s, INF, t); 
    } 
    return flow; 
} 
bool use[MAXN]; 
int main() 
{ 
    int t; scanf("%d", &t); 
    while(t--) 
    { 
        int n, m, p; scanf("%d%d%d", &n, &m, &p); 
        init(); 
        for(int i = 0; i < m; i++) 
        { 
            int u, v; 
            scanf("%d%d", &u, &v); 
            if(u == v) continue; 
            addEdge(u+n, v, INF); 
            addEdge(v+n, u, INF); 
        } 
        int S = 0; CLR(use, false); 
        for(int i = 0; i < p; i++) 
        { 
            int v; scanf("%d", &v); 
            use[v] = true; 
            addEdge(v, v+n, INF); 
            addEdge(S, v, INF); 
        } 
        for(int i = 1; i <= n; i++) if(!use[i]) 
            addEdge(i, i+n, 1); 
        printf("%d\n", Maxflow(S, 1)); 
    } 
    return 0; 
} 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
require([ "esri/Map", "esri/layers/CSVLayer", "esri/views/MapView", "esri/widgets/Legend" ], (Map, CSVLayer, MapView, Legend) => { const url = "https://earthquake.usgs.gov/fdsnws/event/1/query.csv?starttime=2020-01-01%2000:00:00&endtime=2020-12-31%2023:59:59&minlatitude=28.032&maxlatitude=41.509&minlongitude=74.18&maxlongitude=115.857&minmagnitude=2.5&orderby=time"; // Paste the url into a browser's address bar to download and view the attributes // in the CSV file. These attributes include: // * mag - magnitude // * type - earthquake or other event such as nuclear test // * place - location of the event // * time - the time of the event const template = { title: "{place}", content: "Magnitude {mag} {type} hit {place} on {time}." }; // The heatmap renderer assigns each pixel in the view with // an intensity value. The ratio of that intensity value // to the maxPixel intensity is used to assign a color // from the continuous color ramp in the colorStops property const renderer = { type: "heatmap", colorStops: [ { color: "rgba(63, 40, 102, 0)", ratio: 0 }, { color: "#472b77", ratio: 0.083 }, { color: "#4e2d87", ratio: 0.166 }, { color: "#563098", ratio: 0.249 }, { color: "#5d32a8", ratio: 0.332 }, { color: "#6735be", ratio: 0.415 }, { color: "#7139d4", ratio: 0.498 }, { color: "#7b3ce9", ratio: 0.581 }, { color: "#853fff", ratio: 0.664 }, { color: "#a46fbf", ratio: 0.747 }, { color: "#c29f80", ratio: 0.83 }, { color: "#e0cf40", ratio: 0.913 }, { color: "#ffff00", ratio: 1 } ], maxDensity: 0.01, minDensity: 0 }; const layer = new CSVLayer({ url: url, title: "Magnitude 2.5+ earthquakes from the last week", copyright: "USGS Earthquakes", popupTemplate: template, renderer: renderer, labelsVisible: true, labelingInfo: [ { symbol: { type: "text", // autocasts as new TextSymbol() color: "white", font: { family: "Noto Sans", size: 8 }, haloColor: "#472b77", haloSize: 0.75 }, labelPlacement: "center-center", labelExpressionInfo: { expression: "Text($feature.mag, '#.0')" }, where: "mag > 5" } ] }); const map = new Map({ basemap: "gray-vector", layers: [layer] }); const view = new MapView({ container: "viewDiv", center: [-138, 30], zoom: 2, map: map }); view.ui.add( new Legend({ view: view }), "bottom-left" ); }); </script>怎么把这段代码中引用的地址改成本地内存的地址
最新发布
06-08
要将此代码中引用的地址改为本地内存地址,需要先下载该 CSV 文件并将其保存在本地。然后,可以使用 File 对象将文件读入内存中,并使用 URL.createObjectURL() 方法将其转换为可用于加载图层的 URL。以下是修改后的代码示例: ```javascript require([ "esri/Map", "esri/layers/CSVLayer", "esri/views/MapView", "esri/widgets/Legend" ], function(Map, CSVLayer, MapView, Legend) { // 先将 CSV 文件下载并保存在本地 // 然后读取文件并将其转换为可用于加载图层的 URL var file = "/path/to/your/local/file.csv"; var url = URL.createObjectURL(file); // 弹出窗口模板设置 var template = { title: "{place}", content: "Magnitude {mag} {type} hit {place} on {time}." }; // 热力图渲染器设置 var renderer = { type: "heatmap", colorStops: [ { color: "rgba(63, 40, 102, 0)", ratio: 0 }, { color: "#472b77", ratio: 0.083 }, { color: "#4e2d87", ratio: 0.166 }, { color: "#563098", ratio: 0.249 }, { color: "#5d32a8", ratio: 0.332 }, { color: "#6735be", ratio: 0.415 }, { color: "#7139d4", ratio: 0.498 }, { color: "#7b3ce9", ratio: 0.581 }, { color: "#853fff", ratio: 0.664 }, { color: "#a46fbf", ratio: 0.747 }, { color: "#c29f80", ratio: 0.83 }, { color: "#e0cf40", ratio: 0.913 }, { color: "#ffff00", ratio: 1 } ], maxDensity: 0.01, minDensity: 0 }; // CSVLayer 设置 var layer = new CSVLayer({ url: url, title: "Magnitude 2.5+ earthquakes from the last week", popupTemplate: template, renderer: renderer, labelsVisible: true, labelingInfo: [ { symbol: { type: "text", color: "white", font: { family: "Noto Sans", size: 8 }, haloColor: "#472b77", haloSize: 0.75 }, labelPlacement: "center-center", labelExpressionInfo: { expression: "Text($feature.mag, '#.0')" }, where: "mag > 5" } ] }); // Map 和 MapView 设置 var map = new Map({ basemap: "gray-vector", layers: [layer] }); var view = new MapView({ container: "viewDiv", center: [-138, 30], zoom: 2, map: map }); // 添加图例 view.ui.add(new Legend({ view: view }), "bottom-left"); }); ``` 注意:上述代码中的 "file" 变量需要替换为实际的文件路径。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值