Exam 4895 Crowd Control

Posted acerkoo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Exam 4895 Crowd Control相关的知识,希望对你有一定的参考价值。

问题 C: Crowd Control

时间限制: 1 Sec  内存限制: 128 MB
提交: 113  解决: 26
[提交] [状态] [讨论版] [命题人:admin]

题目描述

The BAPC draws a large number of visitors to Amsterdam. Many of these people arrive at the train station, then walk from intersection to intersection through the streets of Amsterdam in a big parade until they reach the BAPC location.

A street can only allow a certain number of people per hour to pass through. This is called the capacity of the street. The number of people going through a street must never exceed its capacity, otherwise accidents will happen. People may walk through a street in either direction.

The BAPC organizers want to prepare a single path from train station to BAPC location. They choose the path with maximum capacity, where the capacity of a path is de?ned to be the minimum capacity of any street on the path. To make sure that nobody walks the wrong way, the organizers close down the streets which are incident
1 to an intersection on the path,but not part of the path.

Can you write a program to help the organizers decide which streets to block? Given a graph of the streets and intersections of Amsterdam, produce the list of streets that need to be closed down in order to create a single maximum-capacity path from the train station to the BAPC. The path must be simple, i.e. it may not visit any  intersection more than once.

 

输入

? The ?rst line contains two integers: n, the number of intersections in the city, and m,the number of streets (1 ≤ n, m ≤ 1000).
? The following m lines each specify a single street. A street is speci?ed by three integers, ai, bi and ci, where ai and bi are ids of the two intersections that are connected by this street (0 ≤ ai, bi < n) and ci is the capacity of this street (1 ≤ ci ≤ 500000). Streets are numbered from 0 to m ? 1 in the given order.
You may assume the following:
? All visitors start walking at the train station which is the intersection with id 0. The BAPC is located at the intersection with id n ? 1.
? The intersections and streets form a connected graph.
? No two streets connect the same pair of intersections.
? No street leads back to the same intersection on both ends.
? There is a unique simple path of maximum capacity.

 

输出

Output a single line containing a list of space separated street numbers that need to be blocked in order to create a single maximum-capacity path from train station to BAPC. Sort these street numbers in increasing order.
If no street must be blocked, output the word “none” instead.
技术分享图片

 

样例输入

7 10
0 1 800
1 2 300
2 3 75
3 4 80
4 5 50
4 6 100
6 1 35
0 6 10
0 2 120
0 3 100

 

样例输出

0 2 4 6 7 8

 

思路:

通过二分找到满足条件的唯一边,将这条边标记,然后统计与这条边相邻的其他边。

 

代码如下:

技术分享图片
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e3+10;
struct node{int u,v,w,next;}e[maxn];
int head[maxn],cnt=0;
inline void add(int u,int v,int w) {e[cnt]=node{u,v,w,head[u]},head[u]=cnt++;}
int pre[maxn],dis[maxn];
int n,m;
bool vis[maxn];
bool vi[maxn];
bool bfs(int mid){
    memset(vis,false,sizeof(vis));
    vis[0]=1;
    queue<int>q;
    q.push(0);
    while(!q.empty()){
        int u=q.front();q.pop();
        for (int v,i=head[u]; ~i; i=e[i].next){
            v=e[i].v;
            if(vis[v]) continue;
            if(e[i].w>=mid) {
                vis[v]=1;
                pre[v]=i;
                q.push(v);
            }
        }
    }
    return vis[n-1];
}
int main(){
    memset(head,-1,sizeof(head));
    cnt=0;
    scanf("%d%d",&n,&m);
    for (int u,v,w,i=1; i<=m; i++){
        scanf("%d%d%d",&u,&v,&w);
        add(u,v,w);
        add(v,u,w);
    }
  
    int l=0,r=500000;
    while(l<r){
        int mid=l+r>>1;
        if(bfs(mid)) l=mid+1;
        else r=mid;
    }
    memset(vis,false,sizeof(vis));
    for (int u=n-1; u!=0; u=e[pre[u]].u){
        vis[pre[u]]=1;
        vis[pre[u]^1]=1;
    }
    priority_queue<int,vector<int>,greater<int> >st;
    for (int u=n-1;u!=0; u=e[pre[u]].u){
        for (int i=head[u]; ~i; i=e[i].next){
            int v=e[i].v;
            if(!vis[i] && !vi[i/2])
                st.push(i/2),vi[i/2]=1;
        }
    }
    for (int i=head[0]; ~i; i=e[i].next){
        int v=e[i].v;
        if(!vis[i] && !vi[i/2])
            st.push(i/2),vi[i/2]=1;
    }
    memset(vis,false,sizeof(vis));
    int fg=0;
    if(!st.size()) return puts("none"),0;
    while(!st.empty()){
        if(fg) printf(" ");
        printf("%d",st.top());
        st.pop();
        fg=1;
    }
    printf("
");
    return 0;
}
View Code

 



















以上是关于Exam 4895 Crowd Control的主要内容,如果未能解决你的问题,请参考以下文章

Nexus3 集成 crowd 插件

Gitlab和Crowd共享账户集成登入

Docker 安装配置Crowd

Awesome Crowd Counting

Atlassian系列之crowd对接jira,confluence,fisheye单点登录

Python3 实现批量创建 Crowd 用户并分配组