Submission #991812


Source Code Expand

/* -------------------------------- Template -------------------------------- */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }

template<typename T> constexpr T inf = [](){ assert(false); };
// template<> constexpr int inf<int> = 1e9;
// template<> constexpr ll inf<ll> = 1e18;
// template<> constexpr ld inf<ld> = 1e30;

struct yes_no : std::numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

void solve();

int main() {
  std::locale loc(std::locale(), new yes_no);
  std::cout << std::boolalpha << std::setprecision(12) << std::fixed;
  std::cout.imbue(loc);
  solve();
  return 0;
}

using namespace std;

/* -------------------------------- Library -------------------------------- */

class UnionFind {
  vector<int> p;
  int sz;
public:
  UnionFind (int n) : p(n, -1), sz(n) {}
  int root(int x) {
    return p[x] < 0 ? x : p[x] = root(p[x]);
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (p[y] < p[x]) swap(x, y);
    if (p[x] == p[y]) --p[x];
    p[y] = x;
    --sz;
    return true;
  }
  int size() const { return sz; }
};

/* ---------------------------------- Main ---------------------------------- */

void solve() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> m(M);
  REP(i,N) {
    int K, L; cin >> K;
    REP(j,K) {
      cin >> L; --L;
      m[L].push_back(i);
    }
  }
  UnionFind uf(N);
  REP(i,M) {
    const int n = m[i].size();
    REP(j,n-1) {
      uf.unite(m[i][j], m[i][j+1]);
    }
  }
  cout << (uf.size() == 1) << endl;
  return;
}

Submission Info

Submission Time
Task C - Interpretation
User asi1024
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2522 Byte
Status AC
Exec Time 53 ms
Memory 4608 KB

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 200 / 200 200 / 200
Status
AC × 2
AC × 12
AC × 25
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
Case Name Status Exec Time Memory
01-01.txt AC 3 ms 256 KB
01-02.txt AC 3 ms 256 KB
01-03.txt AC 3 ms 256 KB
01-04.txt AC 3 ms 256 KB
01-05.txt AC 3 ms 256 KB
01-06.txt AC 3 ms 256 KB
01-07.txt AC 3 ms 256 KB
01-08.txt AC 3 ms 256 KB
01-09.txt AC 3 ms 256 KB
01-10.txt AC 3 ms 256 KB
02-01.txt AC 44 ms 4608 KB
02-02.txt AC 41 ms 1280 KB
02-03.txt AC 42 ms 2816 KB
02-04.txt AC 53 ms 4224 KB
02-05.txt AC 46 ms 1536 KB
02-06.txt AC 53 ms 4224 KB
02-07.txt AC 47 ms 1664 KB
02-08.txt AC 35 ms 1124 KB
02-09.txt AC 51 ms 3448 KB
02-10.txt AC 44 ms 3456 KB
02-11.txt AC 44 ms 3456 KB
02-12.txt AC 43 ms 3328 KB
02-13.txt AC 43 ms 3328 KB
sample-01.txt AC 3 ms 256 KB
sample-02.txt AC 3 ms 256 KB