Submission #7345678


Source Code Expand

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
#include <queue>
#include <stack>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

class Graph{
public:

Graph(long long int o_size){
    graph_size=o_size;
    node.resize(graph_size,0);
    edge.resize(graph_size);
}

long long int add_edge(long long int a,long long int b){
    edge[a].push_back(b);
    edge[b].push_back(a);
        
    return a+b;
}

long long int node_add(long long int i,long long int a){
    node[i]+=a;
    return node[i];
}

void dfs(long long int start){
    vector<bool> checked(graph_size,false);
    stack<long long int> st;
    st.push(start);
    while(st.size()){
        long long int where = st.top();
        //cout << "Unko" << endl;
        st.pop();
        checked[where] = true;

        node[where]++;
        
        
        
        //cout << where << endl;
        for(auto x:edge[where]){
            if(checked[x]==false){
                st.push( x);
               
            }
        }
        
    }

}

void print(long long int n){
REP(i,n){
    if(node[i]==0){
        cout << "NO" << endl;
        return;
    }
}
cout << "YES" << endl;
}


private:
vector<vector<long long int>> edge;
vector<long long int> node;
long long int graph_size;

};

int main(){

    long long int n,m,tmpa,tmpb;
    cin>>n>>m;
    Graph graph(n+m);
    REP(i,n){

        scanf("%lld",&tmpa);
        REP(j,tmpa){
            scanf("%lld", &tmpb);
            graph.add_edge(i,n+tmpb-1);
        }
    }

    graph.dfs(0);
    graph.print(n);

    return 0;
}

Submission Info

Submission Time
Task C - Interpretation
User alumina_8
Language C++14 (Clang 3.8.0)
Score 400
Code Size 2467 Byte
Status AC
Exec Time 38 ms
Memory 11252 KB

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 200 / 200 200 / 200
Status
AC × 2
AC × 12
AC × 27
Set Name Test Cases
sample sample-01.txt, sample-02.txt
dataset1 sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt
dataset2 sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, sample-01.txt, sample-02.txt
Case Name Status Exec Time Memory
01-01.txt AC 1 ms 256 KB
01-02.txt AC 1 ms 384 KB
01-03.txt AC 1 ms 384 KB
01-04.txt AC 1 ms 384 KB
01-05.txt AC 1 ms 384 KB
01-06.txt AC 1 ms 384 KB
01-07.txt AC 1 ms 384 KB
01-08.txt AC 1 ms 384 KB
01-09.txt AC 1 ms 384 KB
01-10.txt AC 1 ms 384 KB
02-01.txt AC 31 ms 7424 KB
02-02.txt AC 30 ms 7808 KB
02-03.txt AC 29 ms 5632 KB
02-04.txt AC 38 ms 8704 KB
02-05.txt AC 34 ms 7168 KB
02-06.txt AC 36 ms 8704 KB
02-07.txt AC 35 ms 7552 KB
02-08.txt AC 27 ms 7664 KB
02-09.txt AC 31 ms 11252 KB
02-10.txt AC 26 ms 7796 KB
02-11.txt AC 26 ms 7924 KB
02-12.txt AC 26 ms 7424 KB
02-13.txt AC 26 ms 7680 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB