Submission #5338039


Source Code Expand

#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

using edge = struct{ll from, to;};

int main(){
    ll N, M; cin >> N >> M;
    vvl l2v(M); // [lan][ver]
    vvl v2l(N);
    
    REP(i, N){
        ll K; cin >> K;
        REP(j, K){
            ll l; cin >> l; l--; l2v[l].pb(i);
            v2l[i].pb(l);
        }
    }
    priority_queue<PL, vector<PL>, greater<PL>> que;
    vl dist(N, LINF); dist[0] = 0;
    que.push({0, 0});
    while(!que.empty()){
        auto curp = que.top(); que.pop();
        ll cur = curp.ss;
        if(dist[cur] < curp.ff) continue;
        for(ll lan : v2l[cur]){
            for(ll ver : l2v[lan]){
                if(dist[ver] > dist[cur] + 1){
                    dist[ver] = 1;
                    que.push({dist[ver], ver});
                }
            }
        }
    }
    bool ok = true;
    REP(i, N){
        if(dist[i] > 2) ok = false;
    }
    cout << (ok ? "YES" : "NO") << endl;
    return 0;
}

Submission Info

Submission Time
Task C - Interpretation
User k_k_hiroki
Language C++14 (GCC 5.4.1)
Score 200
Code Size 2899 Byte
Status TLE
Exec Time 2104 ms
Memory 11764 KB

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 200 / 200 0 / 200
Status
AC × 2
AC × 12
AC × 23
TLE × 4
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 2 ms 256 KB
01-03.txt AC 2 ms 384 KB
01-04.txt AC 2 ms 384 KB
01-05.txt AC 2 ms 384 KB
01-06.txt AC 2 ms 384 KB
01-07.txt AC 2 ms 256 KB
01-08.txt AC 2 ms 384 KB
01-09.txt AC 2 ms 256 KB
01-10.txt AC 2 ms 384 KB
02-01.txt AC 45 ms 6272 KB
02-02.txt AC 84 ms 8572 KB
02-03.txt AC 46 ms 4992 KB
02-04.txt AC 63 ms 7936 KB
02-05.txt AC 70 ms 7932 KB
02-06.txt AC 64 ms 7936 KB
02-07.txt AC 68 ms 7552 KB
02-08.txt TLE 2104 ms 8432 KB
02-09.txt TLE 2104 ms 11764 KB
02-10.txt TLE 2104 ms 8052 KB
02-11.txt TLE 2104 ms 8052 KB
02-12.txt AC 512 ms 7420 KB
02-13.txt AC 510 ms 7420 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB