• BC#53 1001 Rikka with Graph


    Rikka with Graph

     
     Accepts: 353
     
     Submissions: 1174
     Time Limit: 2000/1000 MS (Java/Others)
     
     Memory Limit: 65536/65536 K (Java/Others)
    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 nn vertices and mm 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 nn. 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(2 leq n leq 100, 0 leq m leq 100)n,m(2n100,0m100).

    Then mm lines follow. Each line contains two numbers u,v(1 leq u,v leq n)u,v(1u,vn) , which means there is an edge between uu and vv. 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 nn and the number of the ways of adding this edge.

    Sample Input
    2 1
    1 2
    Sample Output
    1 1
    Hint
    You can only add an edge between 1 and 2.
     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <algorithm>
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     int n,m;
     9     int i,j,k;
    10     while(scanf("%d %d",&n,&m)!=EOF)
    11     {
    12         int flg=0;
    13         for(i=1;i<=m;i++)
    14         {
    15             int x,y;
    16             scanf("%d %d",&x,&y);
    17             if((x==1 && y==n)|| (x==n && y==1))
    18                 flg=1;
    19         }
    20         if(flg==0)
    21             printf("1 1
    ");
    22         else
    23             printf("1 %d
    ",n*(n-1)/2);
    24     }
    25     return 0;
    26 }
    View Code
  • 相关阅读:
    设计模式——代理模式
    设计模式——建造者模式
    设计模式——模板方法
    springboot+mybatis项目自动生成
    【小坑】java下载excel文件
    设计模式——工厂方法模式 和 抽象工厂模式
    设计模式——单例模式
    容易忽略的递归当中的return
    Android 4.0以后正确的获取外部sd卡存储目录
    Android 串口设置校验位、速率、停止位等参数
  • 原文地址:https://www.cnblogs.com/cyd308/p/4770786.html
Copyright © 2020-2023  润新知