1. 程式人生 > >1134. Vertex Cover (25)

1134. Vertex Cover (25)

pre ostream else span blog pause ios bre spa

稍微做一點點手腳就不會超時了。。。還是挺簡單的,考試時候也做出來了。。。

#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"); }

1134. Vertex Cover (25)