zoukankan      html  css  js  c++  java
  • Codeforces Round #192 (Div. 2) (330B) B.Road Construction

    题意:

         要在N个城市之间修建道路,使得任意两个城市都可以到达,而且不超过两条路,还有,有些城市之间是不能修建道路的。

    思路:

        要将N个城市全部相连,刚开始以为是最小生成树的问题,其实就是一道简单的题目。  要求两个城市之间不超过两条道路,那么所有的城市应该是连在一个点上的,至于这个点就很好找了,只要找到一个没有和其他点有道路限制的即可。

    //cf 192 B
    #include <stdio.h>
    #include <string.h>
    
    char map[1005][1005];
    
    int main()
    {
        int n, m;
        while (scanf("%d %d", &n, &m) != EOF)
        {
            int s, e;
            memset(map, 0, sizeof(map));
            for (int i = 1; i <= m; i++)
            {
                scanf("%d %d", &s, &e);
                map[s][e] = 1;
                map[e][s] = 1;
            }
            int x;
            for (int i = 1; i <= n; i++)
            {
                int flag = 1;
                for (int j = 1; j <= n; j++)
                {
                    if (map[i][j])
                    {
                        flag = 0;
                        break;
                    }
                }
                if (flag)
                {
                    x = i;
                    break;
                }
            }
            printf("%d
    ", n-1);
            for (int i = 1; i <= n; i++)
            {
                if (x == i)
                    continue;
                else
                    printf("%d %d
    ", x, i);
            }
        }
        return 0;
    }


  • 相关阅读:
    基于硬件的毕业设计论文的书写
    C语言程序设计课程总结
    嵌入式程序设计第三周成绩汇总
    C第十八次课
    2016-4班平时成绩第9周排名和汇总
    2016-3班平时成绩第9周汇总和排名
    第十七次课大纲
    第十六次课大纲
    2020-02-28
    2020-02-27
  • 原文地址:https://www.cnblogs.com/xindoo/p/3595061.html
Copyright © 2011-2022 走看看