UPC-5211 - The Maximum Unreachable Node Set - 最小路径覆盖

原创 2018年04月15日 11:22:55

题解链接:

https://lucien.ink/archives/151/


题目链接:

http://exam.upc.edu.cn/problem.php?id=5211


题目:

题目描述

In this problem, we would like to talk about unreachable sets of a directed acyclic graph G = (V, E). In mathematics a directed acyclic graph (DAG) is a directed graph with no directed cycles. That is a graph such that there is no way to start at any node and follow a consistently-directed sequence of edges in E that eventually loops back to the beginning again.
A node set denoted by V UR ⊂ V containing several nodes is known as an unreachable node set of G if, for each two different nodes u and v in V UR , there is no way to start at u and follow a consistently-directed sequence of edges in E that finally archives the node v. You are asked in this problem to calculate the size of the maximum unreachable node set of a given graph G.

输入

The input contains several test cases and the first line contains an integer T (1 ≤ T ≤ 500) which is the number of test cases.
For each case, the first line contains two integers n (1 ≤ n ≤ 100) and m (0 ≤ m ≤ n(n − 1)/2) indicating the number of nodes and the number of edges in the graph G. Each of the following m lines describes a directed edge with two integers u and v (1 ≤ u, v ≤ n and u 6= v) indicating an edge from the u-th node to the v-th node. All edges provided in this case are distinct.
We guarantee that all directed graphs given in input are DAGs and the sum of m in input is smaller than 500000.

输出

For each test case, output an integer in a line which is the size of the maximum unreachable node set of G.

样例输入

3
4 4
1 2
1 3
2 4
3 4
4 3
1 2
2 3
3 4
6 5
1 2
4 2
6 2
2 3
2 5

样例输出

2
1
3

题意:

  给你一个n个点,m条边的DAG(有向无环图),定义一个点集A:点集A内的任意一个点都不可到达除自己外的其它点,让你求出这个最大的点集A。


思路:

  求一下最大独立集即可,即:用点的数目减去最小路径覆盖的数目。


实现:

#include <bits/stdc++.h>
const int maxn = 107;
bool map[maxn][maxn], vis[maxn];
int n, m, T, link[maxn];
bool dfs(int u) {
    for (int v = 1; v <= n; v++) {
        if (map[u][v] && !vis[v]) {
            vis[v] = true;
            if (link[v] == -1 || dfs(link[v])) {
                link[v] = u;
                return true;
            }
        }
    }
    return false;
}
int solve() {
    int ans = 0;
    memset(link, 0xff, sizeof(link));
    for (int i = 1; i <= n; i++) {
        memset(vis, false, sizeof(vis));
        ans += dfs(i);
    }
    return ans;
}
int main() {
//    freopen("in.txt", "r", stdin);
    scanf("%d", &T);
    while (memset(map, false, sizeof(map)), T--) {
        scanf("%d%d", &n, &m);
        for (int i = 0, u, v; i < m; i++) scanf("%d%d", &u, &v), map[u][v] = true;
        for (int k = 1; k <= n; k++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) map[i][j] |= map[i][k] & map[k][j];
        printf("%d\n", n - solve());
    }
    return 0;
}
版权声明:来自lucien.ink,转载请注明文章出处。 https://blog.csdn.net/xs18952904/article/details/79947697

2017ICPC南宁 M题 The Maximum Unreachable Node Set [二分图最大独立集]

2017ICPC南宁 M题 The Maximum Unreachable Node Set [二分图最大独立集]
  • ACTerminate
  • ACTerminate
  • 2018-02-04 14:59:05
  • 136

2017 ICPC 南宁 M题 The Maximum Unreachable Node Set (二分图匹配)

The Maximum Unreachable Node Set时间限制: 20 Sec  内存限制: 128 MB提交: 51  解决: 8[提交][状态][讨论版][命题人:admin]题目描述I...
  • Ever_glow
  • Ever_glow
  • 2018-04-07 11:30:11
  • 52

2017 ICPC南宁站 M题The Maximum Unreachable Node Set(二分图)

题目:https://nanti.jisuanke.com/t/19979In this problem, we would like to talk about unreachable sets o...
  • winter2121
  • winter2121
  • 2018-04-08 11:37:01
  • 47

The Maximum Unreachable Node Set

In this problem, we would like to talk about unreachable sets of a directed acyclic graph G = (V,E)G...
  • a664607530
  • a664607530
  • 2018-04-19 19:21:08
  • 8

遇到的情况--hive---动态创建分区报错dynamic.partitions.pernode. Maximum was set to: 100

遇到的情况 我们在hive shell中使用 insert overwrite table table_p partition(time) select id,time from tabl...
  • q383965374
  • q383965374
  • 2018-03-03 10:05:25
  • 163

Bug 11775332 - cluvfy fails with PRVF-5636 with DNS response timeout error [ID 11775332.8]

Bug 11775332  cluvfy fails with PRVF-5636 withDNS response timeout error but error text is not clear...
  • xiangsir
  • xiangsir
  • 2013-06-23 10:18:13
  • 3778

PRVF-5636 : The DNS response time for an unreachable node exceeded "15000" ms on following nodes

In this Document   Purpose   Details   References ...
  • u010098331
  • u010098331
  • 2016-03-11 15:08:54
  • 1815

Binary Tree Maximum Node

Find the maximum node in a binary tree, return the node. Given a binary tree: 1 / \ ...
  • u013289254
  • u013289254
  • 2017-03-16 19:15:43
  • 324

LintCode | 632. Binary Tree Maximum Node

ind the maximum node in a binary tree, return the node. 水题一道,直接po代码public class Solution { public...
  • orz_713
  • orz_713
  • 2017-03-07 19:01:32
  • 728

linux oracle 安装错误 系统参数小于要求的参数 Error Message:PRVF-4353 PRVF-4354

这篇文章献给死读书自己
  • mjj291268154
  • mjj291268154
  • 2014-05-24 13:10:13
  • 4026
收藏助手
不良信息举报
您举报文章:UPC-5211 - The Maximum Unreachable Node Set - 最小路径覆盖
举报原因:
原因补充:

(最多只允许输入30个字)