zoukankan      html  css  js  c++  java
  • HDU 5422 Rikka with Graph

    Rikka with Graph

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 182    Accepted Submission(s): 95

    Problem Description
    As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:
    Yuta has a non-direct graph with n
    vertices and m
    edges. The length of each edge is 1. Now he wants to add exactly an edge which connects two different vertices and minimize the length of the shortest path between vertice 1 and vertice n
    . Now he wants to know the minimal length of the shortest path and the number of the ways of adding this edge.
    It is too difficult for Rikka. Can you help her?
     
    Input
    There are no more than 100 testcases.
    For each testcase, the first line contains two numbers n,m(2n100,0m100)
    .
    Then m
    lines follow. Each line contains two numbers u,v(1u,vn)
    , which means there is an edge between u
    and v
    . There may be multiedges and self loops.
     
    Output
    For each testcase, print a single line contains two numbers: The length of the shortest path between vertice 1 and vertice n
    and the number of the ways of adding this edge.
     
    Sample Input
    2 1
    1 2
    Sample Output
    1 1
    这道题看似是一个图论题, 然而仔细一看就水的不行啦。 如果 1 和点 n 没有直接相连的路径, 那么最短路径就是这一条。 否则,最短路径还是这一条。 但是连线的方案确是任意乱连都可以。有 n*(n-1)/2个连法。
    当时对题意理解错啦:  理解为添加一条路径使1到其他点路径的总和最小。 (呜呜呜呜~~~~)
    #include<iostream>
    #include<cstdio>
    using namespace std;
    
    int main()
    {
        int m, n;
        while(~scanf("%d%d", &n, &m))
        {
            int u, v;
            int ok = 0;
            for(int i=0; i<m; i++)
            {
                scanf("%d%d", &u, &v);
                if((u==1&&v==n)||(v==1&&u==n))
                ok = 1;
            }
            if(!ok) printf("%d %d
    ",1, 1);
            else printf("%d %d
    ",1, n*(n-1)/2);
        }
        return 0;
    } 
  • 相关阅读:
    git常用命令
    Vue路由传参的几种方式
    yum安装之-安装mysql
    Xshell连接不上Ubuntu解决方式 --转
    ubuntu 命令行模式和图形界面切换 --转
    yum安装之-安装底层软件库
    VMware虚拟机 CentOS 6.5系统安装配置详细图文教程 --技术支持TPshop商城
    vmware虚拟机怎么新建虚拟机--技术支持TPshop商城
    TPshop商城使用,TPshop商城使用的安装
    tpshop商城根据用户坐标,向数据库查找附近的商家
  • 原文地址:https://www.cnblogs.com/acm1314/p/4770446.html
Copyright © 2011-2022 走看看