L2-025 分而治之

作者: smatrcHendsa | 来源:发表于2019-03-17 09:44 被阅读0次

    血亏 一道基础题目 多输出了东西导致只拿了7分
    https://pintia.cn/problem-sets/994805046380707840/problems/994805056195379200

    #include <stdio.h>
    #include <iostream>
    #include <cstring>
    #include <vector>
    #include <queue>
    #include <map>
    #include <set>
    #include <sstream>
    #include <algorithm>
    using namespace std;
    int N, M;
    //const int MAXN = , MAXM = 0;
    //typedef long long ll;
    const int si = 10007;
    vector <int> G[si];
    int gongxia[si];
    
    int flag = 0;
    void solve() {
        int cnt = 0;
        for (int i = 1; i <= N; i++) {
            flag = 0;
            if (gongxia[i]) continue;
            for (int j = 0; j < G[i].size(); j++) {
                int to = G[i][j];
                if (!gongxia[to]) {
                    flag = 1;
                    return;
                }
            }
        }
    }
    
    int main() {
        int a, b, k;
        scanf("%d %d", &N, &M);
        for (int i = 0; i < M; i++) {
            scanf("%d %d", &a, &b);
            G[a].push_back(b);
            G[b].push_back(a);
        }
        for (int i = 1; i <= N; i++) {
            if (G[i].size() == 0) {
                gongxia[i] = 1;
            //  cout << i;
            }
        }
        cin >> k;
        for (int i = 0, b; i < k; i++) {
            fill(gongxia, gongxia + si, 0);
            cin >> b;
            for (int j = 0, tep; j < b; j++) {
                scanf("%d", &tep);
                gongxia[tep] = 1;
            }
            solve();
            if (flag) printf("NO\n");
            else printf("YES\n");
        }
    
        return 0;
    }
    

    相关文章

      网友评论

        本文标题:L2-025 分而治之

        本文链接:https://www.haomeiwen.com/subject/rcmymqtx.html