Kingdom

Problem Description
Teacher Mai has a kingdom consisting of n cities. He has planned the transportation of the kingdom. Every pair of cities has exactly a one-way road.

He wants develop this kingdom from one city to one city.

Teacher Mai now is considering developing the city w. And he hopes that for every city u he has developed, there is a one-way road from u to w, or there are two one-way roads from u to v, and from v to w, where city v has been developed before.

He gives you the map of the kingdom. Hope you can give a proper order to develop this kingdom.

 

Input
There are multiple test cases, terminated by a line "0".

For each test case, the first line contains an integer n (1<=n<=500).

The following are n lines, the i-th line contains a string consisting of n characters. If the j-th characters is 1, there is a one-way road from city i to city j.

Cities are labelled from 1.

 

Output
If there is no solution just output "-1". Otherwise output n integers representing the order to develop this kingdom.
 

Sample Input
3 011 001 000 0
 

Sample Output
1 2 3

题意 :给出一个图满足两两之间都有一条边,然后选择建设的城市,满足当前选的城市和之前选的城市之间最多距离为2.  求建设城市的顺序。

sl :刚开始傻逼了没看到红色的话,比赛的时候更傻逼,提都理解错了。妈蛋白敲了100+代码。 其实选下最大度数的节点就好了,证明就是题解

的那个证明,反证。因为确保都有一条边所以题解是对的,我说开始为什么看着不对呢

#include <cstdio>

#include <cstring>
#include <algorithm>
#include <vector>
#include <vector>
using namespace std;
const int inf = 0x3f3f3f3f;
const int MAX = +;
char str[MAX][MAX];
int in[MAX],vis[MAX],G[MAX][MAX];
vector<int> res;
int main() {
    int n;
    while(scanf("%d",&n)==&&n) {
        memset(G,,sizeof(G));
        memset(vis,,sizeof(vis));
        memset(in,,sizeof(in));
        res.clear();
        for(int i=;i<=n;i++) {
            scanf("%s",str[i]+);
        }
        for(int i=;i<=n;i++) {
            for(int j=;j<=n;j++) {
                if(str[i][j]=='') {
                     G[i][j]=; in[j]++;
                }
            }
        }
        for(int i=;i<=n;i++) {
            int node,Max=;
            for(int j=;j<=n;j++) {
                if(!vis[j]) {
                    if(Max<=in[j]) {
                        node=j; Max=in[j];
                    }
                }
            }
            for(int j=;j<=n;j++) if(G[node][j]) in[j]--;
            vis[node]=;
            res.push_back(node);
        }
       // printf("s");
        for(int i=res.size()-;i>=;i--) {
            if(!i) printf("%d\n",res[i]);
            else printf("%d ",res[i]);
        }
    }
    return ;
}

HDU 4948 (傻比图论)的更多相关文章

  1. hdu 4948 Kingdom(推论)

    hdu 4948 Kingdom(推论) 传送门 题意: 题目问从一个城市u到一个新的城市v的必要条件是存在 以下两种路径之一 u --> v u --> w -->v 询问任意一种 ...

  2. HDU 5934 Bomb 【图论缩点】(2016年中国大学生程序设计竞赛(杭州))

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  3. HDU 4435 charge-station bfs图论问题

    E - charge-station Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  4. HDU 5961 传递 【图论+拓扑】 (2016年中国大学生程序设计竞赛(合肥))

    传递 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)     Problem ...

  5. 拓扑排序 --- hdu 4948 : Kingdom

    Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  6. HDU 4948

    题目大义: 给一张图,任意两点间有单向边,找出一种方案,使得每个新入队的点与队中的点距离<=2. 题解: 贪心,从最后入队点开始反向插入,每次找出最大入度的点入队. 只需证明最大入度点A与所有未 ...

  7. HDU 2647 Reward(图论-拓扑排序)

    Reward Problem Description Dandelion's uncle is a boss of a factory. As the spring festival is comin ...

  8. HDU 4467 Graph(图论+暴力)(2012 Asia Chengdu Regional Contest)

    Description P. T. Tigris is a student currently studying graph theory. One day, when he was studying ...

  9. hdu 3357 Stock Chase (图论froyd变形)

    Stock Chase Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

随机推荐

  1. 死磕 java魔法类之Unsafe解析

    问题 (1)Unsafe是什么? (2)Unsafe只有CAS的功能吗? (3)Unsafe为什么是不安全的? (4)怎么使用Unsafe? 简介 本章是java并发包专题的第一章,但是第一篇写的却不 ...

  2. UnixTime的时间戳的转换

    public static string XConvertDateTime(double unixTime) { System.DateTime time = System.DateTime.MinV ...

  3. 文件及文件的操作-读、写、追加的t和b模式

    1.什么是文件? 文件是操作系统为用户或应用程序提供的一个读写硬盘的虚拟单位. 文件的操作核心:读和写 对文件进行读写操作就是向操作系统发出指令,操作系统将用户或者应用程序对文件的读写操作转换为具体的 ...

  4. Windows 下 IIS与Apache 共存

    在Windows服务器下, 安装了IIS以及Apache服务器, 如何使他们一起工作. 目前我面对的问题是, 只有一个IP地址,要通过不同的端口来访问不同的程序. 解决方案如下: 1.找到 Apach ...

  5. Ubuntu 下更新或下载输入法(搜狗)

    ubuntu12.04的fcitx版本不支持,不满足依赖,需要更新fcitx 添加fcitx源添加fcitx源命令 : sudo add-apt-repository ppa:fcitx-team/n ...

  6. java 文件另存为

    FileUtils.copyFile(new File(), new File());

  7. 使用迅为iTOP-iMX6开发板-uboot-修改默认环境变量

    iTOP-iMX6 开发板烧写好之后,默认是 android 系统 9.7 寸屏幕的系统参数和屏幕参数.如下图.本文档主要介绍如何修改默认启动参数. 1. 重要的环境变量比较重要的环境变量或者说经常使 ...

  8. swift 多态函数方式

    1.v-table:   class 2.WitnessTable protocol 3.消息派发. @objc dynamic

  9. Discuz3.1登录QQ互联显示redirect uri is illegal(100010)的解决

    QQ互联最近也是BUG不断,引起了很多用户的不满,从早前关闭群组功能,到发布2.0接口标准,引发系列站长用户的连锁反应.而Discuz从X3开始,为了应对QQ互联的2.0接口标准,采用了云平台来整合Q ...

  10. basename - 从文件名中剥离目录和后缀

    总览 (SYNOPSIS) basename NAME [SUFFIX] basename OPTION 描述 (DESCRIPTION) 显示 去掉 目录成分 后的 NAME. 如果 指定了 SUF ...