zoukankan      html  css  js  c++  java
  • 2010 SD

    D - Emergency
    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu
     use MathJax to parse formulas

    Description

    Kudo’s real name is not Kudo. Her name is Kudryavka Anatolyevna Strugatskia, and Kudo is only her nickname.

    Now, she is facing an emergency in her hometown:

    Her mother is developing a new kind of spacecraft. This plan costs enormous energy but finally failed. What’s more, because of the failed project, the government doesn’t have enough resource take measure to the rising sea levels caused by global warming, lead to an island flooded by the sea.

    Dissatisfied with her mother’s spacecraft and the government, civil war has broken out. The foe wants to arrest the spacecraft project’s participants and the “Chief criminal” – Kudo’s mother – Doctor T’s family.

    At the beginning of the war, all the cities are occupied by the foe. But as time goes by, the cities recaptured one by one.

    To prevent from the foe’s arrest and boost morale, Kudo and some other people have to distract from a city to another. Although they can use some other means to transport, the most convenient way is using the inter-city roads. Assuming the city as a node and an inter-city road as an edge, you can treat the map as a weighted directed multigraph. An inter-city road is available if both its endpoint is recaptured.

    Here comes the problem.

    Given the traffic map, and the recaptured situation, can you tell Kudo what’s the shortest path from one city to another only passing the recaptured cities?

    Input

    The input consists of several test cases.

    The first line of input in each test case contains three integers N (0<N300), M (0<M100000) and Q (0<Q100000), which represents the number of cities, the numbers of inter-city roads and the number of operations.

    Each of the next M lines contains three integer x, y and z, represents there is an inter-city road starts from x, end up with y and the length is z. You can assume that 0<z10000.

    Each of the next Q lines contains the operations with the following format:

    a)       x – means city x has just been recaptured.

    b)      x y – means asking the shortest path from x to y only passing the recaptured cities.

    The last case is followed by a line containing three zeros.

    Output

    For each case, print the case number (1, 2 …) first.

    For each operation 0, if city x is already recaptured (that is,the same 0 x operation appears again), print “City x is already recaptured.”

    For each operation 1, if city x or y is not recaptured yet, print “City x or y is not available.” otherwise if Kudo can go from city x to city y only passing the recaptured cities, print the shortest path’s length; otherwise print “No such path.”

    Your output format should imitate the sample output. Print a blank line after each test case.

    Sample Input

    3 3 6
    0 1 1
    1 2 1
    0 2 3
    1 0 2
    0 0
    0 2
    1 0 2
    1 2 0
    0 2
    
     
    
    0 0 0

    Sample Output

    Case 1:
    City 0 or 2 is not available.
    3
    No such path.
    City 2 is already recaptured.

    Hint

     

    明显就是一个floyd变形

    #include <iostream>
    #include <cstdio>
    #include <sstream>
    #include <cstring>
    #include <map>
    #include <cctype>
    #include <set>
    #include <vector>
    #include <stack>
    #include <queue>
    #include <algorithm>
    #include <cmath>
    #include <bitset>
    #define rap(i, a, n) for(int i=a; i<=n; i++)
    #define rep(i, a, n) for(int i=a; i<n; i++)
    #define lap(i, a, n) for(int i=n; i>=a; i--)
    #define lep(i, a, n) for(int i=n; i>a; i--)
    #define rd(a) scanf("%d", &a)
    #define rlld(a) scanf("%lld", &a)
    #define rc(a) scanf("%c", &a)
    #define rs(a) scanf("%s", a)
    #define rb(a) scanf("%lf", &a)
    #define rf(a) scanf("%f", &a)
    #define pd(a) printf("%d
    ", a)
    #define plld(a) printf("%lld
    ", a)
    #define pc(a) printf("%c
    ", a)
    #define ps(a) printf("%s
    ", a)
    #define MOD 2018
    #define LL long long
    #define ULL unsigned long long
    #define Pair pair<int, int>
    #define mem(a, b) memset(a, b, sizeof(a))
    #define _  ios_base::sync_with_stdio(0),cin.tie(0)
    //freopen("1.txt", "r", stdin);
    using namespace std;
    const int maxn = 110000, INF = 0xfffffff;
    int n, m, q;
    bool vis2[maxn], G[330][330];
    int d[330][330];
    
    void floyd(int k)  //更新与点k相关联的所有的距离
    {
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }
    int main()
    {
        int kase = 0;
        while(scanf("%d%d%d", &n, &m, &q))
        {
    
            for(int i = 0; i < n; i++)
                for(int j = i + 1; j < n; j++)
                    d[i][i] = 0, d[i][j] = d[j][i] = INF;
            if(n == 0 && m == 0 && q == 0) break;
            mem(vis2, 0);
            int u, v, w;
            for(int i = 0; i < m; i++)
            {
                rd(u), rd(v), rd(w);
                d[u][v] = min(d[u][v], w);
            }
            printf("Case %d:
    ", ++kase);
    
            int o, x;
            for(int i = 0; i < q; i++)
            {
                rd(o);
                if(o == 0)
                {
                    rd(x);
                    if(!vis2[x]) floyd(x);
                    if(vis2[x]) printf("City %d is already recaptured.
    ", x);
                    vis2[x] = 1;
    
                }
                else if(o == 1)
                {
                    rd(u), rd(v);
                    if(vis2[u] == 0 || vis2[v] == 0)
                        printf("City %d or %d is not available.
    ", u, v);
                    else if(d[u][v] == INF) printf("No such path.
    ");
                    else
                    {
                        printf("%d
    ", d[u][v]);
    
                    }
    
                }
    
    
            }
    
            printf("
    ");
    
        }
    
    
        return 0;
    }

     

    D - Emergency
    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu
     use MathJax to parse formulas

    Description

    Kudo’s real name is not Kudo. Her name is Kudryavka Anatolyevna Strugatskia, and Kudo is only her nickname.

    Now, she is facing an emergency in her hometown:

    Her mother is developing a new kind of spacecraft. This plan costs enormous energy but finally failed. What’s more, because of the failed project, the government doesn’t have enough resource take measure to the rising sea levels caused by global warming, lead to an island flooded by the sea.

    Dissatisfied with her mother’s spacecraft and the government, civil war has broken out. The foe wants to arrest the spacecraft project’s participants and the “Chief criminal” – Kudo’s mother – Doctor T’s family.

    At the beginning of the war, all the cities are occupied by the foe. But as time goes by, the cities recaptured one by one.

    To prevent from the foe’s arrest and boost morale, Kudo and some other people have to distract from a city to another. Although they can use some other means to transport, the most convenient way is using the inter-city roads. Assuming the city as a node and an inter-city road as an edge, you can treat the map as a weighted directed multigraph. An inter-city road is available if both its endpoint is recaptured.

    Here comes the problem.

    Given the traffic map, and the recaptured situation, can you tell Kudo what’s the shortest path from one city to another only passing the recaptured cities?

    Input

    The input consists of several test cases.

    The first line of input in each test case contains three integers N (0<N300), M (0<M100000) and Q (0<Q100000), which represents the number of cities, the numbers of inter-city roads and the number of operations.

    Each of the next M lines contains three integer x, y and z, represents there is an inter-city road starts from x, end up with y and the length is z. You can assume that 0<z10000.

    Each of the next Q lines contains the operations with the following format:

    a)       x – means city x has just been recaptured.

    b)      x y – means asking the shortest path from x to y only passing the recaptured cities.

    The last case is followed by a line containing three zeros.

    Output

    For each case, print the case number (1, 2 …) first.

    For each operation 0, if city x is already recaptured (that is,the same 0 x operation appears again), print “City x is already recaptured.”

    For each operation 1, if city x or y is not recaptured yet, print “City x or y is not available.” otherwise if Kudo can go from city x to city y only passing the recaptured cities, print the shortest path’s length; otherwise print “No such path.”

    Your output format should imitate the sample output. Print a blank line after each test case.

    Sample Input

    3 3 6
    0 1 1
    1 2 1
    0 2 3
    1 0 2
    0 0
    0 2
    1 0 2
    1 2 0
    0 2
    
     
    
    0 0 0

    Sample Output

    Case 1:
    City 0 or 2 is not available.
    3
    No such path.
    City 2 is already recaptured.

    Hint

    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    P4016 负载平衡问题 网络流
    P3357 最长k可重线段集问题 网络流
    mysql部署
    pve配置
    PVE手册资料
    PVE授权条款
    ovirt磁盘类型(IDE, virtio, virtio-scsi)
    oVirt-postgresql
    ovirt常用后台维护命令
    oVirt部署
  • 原文地址:https://www.cnblogs.com/WTSRUVF/p/10678907.html
Copyright © 2011-2022 走看看