zoukankan      html  css  js  c++  java
  • 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 defined 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 first 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 specified 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
  • 相关阅读:
    Linux中的yum是什么?如何配置?如何使用?
    Nginx + tornado + supervisor部署
    python3 实现mysql数据库连接池
    零代码如何打造自己的实时监控预警系统
    一步一步在Windows中使用MyCat负载均衡 上篇
    你真的会玩SQL吗?之逻辑查询处理阶段
    徒手教你制作运维监控大屏
    Jenkins+GitLab+Docker+SpringCloud+Kubernetes实现可持续自动化微服务
    容器化之Docker小知识普及
    Kubernetes知识小普及
  • 原文地址:https://www.cnblogs.com/acerkoo/p/9532279.html
Copyright © 2011-2022 走看看