1134. Vertex Cover (25)

稍微做一点点手脚就不会超时了。。。还是挺简单的,考试时候也做出来了。。。

#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;

const int inf = 99999999;

int main() {

    int v, e;
    cin >> v >> e;
    int check[10001];
    vector<int> m1[10001];

    for (int i = 0; i < e; i++) {
        int n1, n2;
        cin >> n1 >> n2;

        m1[n1].push_back(i);
        m1[n2].push_back(i);
    }

    int num;
    cin >> num;

    for (int i = 0; i < num; i++) {
        fill(check, check + 10001, 0);

        int n;
        cin >> n;
        for (int j = 0; j < n; j++) {
            int k;
            cin >> k;
            for (int p = 0; p < m1[k].size(); p++) {
                check[m1[k][p]] = 1;
            }
        }
        bool f = 1;
        for (int q = 0; q < e; q++) {
            if (check[q] == 0) {
                f = 0;
                break;
            }
        }

        if (f == 0) {
            cout << "No" << endl;
        }

        else {
            cout << "Yes" << endl;
        }
    }

    system("pause");
}
时间: 2024-10-13 22:49:15

1134. Vertex Cover (25)的相关文章

1134 Vertex Cover (25 分)

1134 Vertex Cover (25 分) A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at least one vertex of the set. Now given a graph with several vertex sets, you are supposed to tell if each of them is a vertex c

PAT 1134 Vertex Cover

A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at least one vertex of the set. Now given a graph with several vertex sets, you are supposed to tell if each of them is a vertex cover or not. Input Specif

二分图匹配 + 最小点覆盖 - Vertex Cover

Vertex Cover Problem's Link Mean: 给你一个无向图,让你给图中的结点染色,使得:每条边的两个顶点至少有一个顶点被染色.求最少的染色顶点数. analyse: 裸的最小点覆盖问题,二分图的最大匹配,直接套模版即可. Time complexity: O(N^2) view code

URAL 2038 Minimum Vertex Cover

2038. Minimum Vertex Cover Time limit: 1.0 secondMemory limit: 64 MB A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at least one vertex of the set. A minimum vertex cover is a vertex cover with minimal

SCU - 4439 Vertex Cover (图的最小点覆盖集)

Vertex Cover frog has a graph with \(n\) vertices \(v(1), v(2), \dots, v(n)\) and \(m\) edges \((v(a_1), v(b_1)), (v(a_2), v(b_2)), \dots, (v(a_m), v(b_m))\). She would like to color some vertices so that each edge has at least one colored vertex. Fi

四川第七届 D Vertex Cover(二分图最小点覆盖,二分匹配模板)

Vertex Cover frog has a graph with nn vertices v(1),v(2),-,v(n)v(1),v(2),-,v(n) and mm edges (v(a1),v(b1)),(v(a2),v(b2)),-,(v(am),v(bm))(v(a1),v(b1)),(v(a2),v(b2)),-,(v(am),v(bm)). She would like to color some vertices so that each edge has at least

PAT Advanced 1154 Vertex Coloring (25 分)

A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices sharing the same edge have the same color. A coloring using at most k colors is called a (proper) k-coloring. Now you are supposed to tell if a given

PAT Advanced 1154 Vertex Coloring (25) [set,hash]

题目 A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices sharing the same edge have the same color. A coloring using at most k colors is called a (proper) k-coloring. Now you are supposed to tell if a gi

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6150 Vertex Cover 二分图,构造

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6150 题意:"最小点覆盖集"是个NP完全问题 有一个近似算法是说-每次选取度数最大的点(如果有多个这样的点,则选择最后一个) 让你构造一个图,使得其近似算法求出来点数是你给定的覆盖点数的至少3倍. 解法: 可以把左边的点编号1~n,将左边的点进行n次分块,第i次分块中每块的大小为i,对于每一块的点,都在右边创建一个新节点与这些点相连. ①右边的点的度数为n,n-1,n-2,...,n/2,