#include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1}; constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}; constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; template struct StronglyConnectedComponents { std::vector id; std::vector> vertices, g; explicit StronglyConnectedComponents( const std::vector>& graph) : n(graph.size()), is_used(n, false), graph(graph), rgraph(n) { order.reserve(n); for (int i = 0; i < n; ++i) { if (!is_used[i]) dfs(i); } id.assign(n, -1); for (int i = 0; i < n; ++i) { for (const int e : graph[i]) rgraph[e].emplace_back(i); } int m = 0; for (int i = n - 1; i >= 0; --i) { if (id[order[i]] == -1) { if constexpr (IS_FULL_VER) vertices.emplace_back(); rdfs(order[i], m++); } } g.resize(m); for (int i = 0; i < n; ++i) { for (const int e : graph[i]) { if (id[i] != id[e]) g[id[i]].emplace_back(id[e]); } } // if constexpr (IS_FULL_VER) { // for (int i = 0; i < m; ++i) { // std::sort(vertices[i].begin(), vertices[i].end()); // } // } } private: const int n; std::vector is_used; std::vector order; std::vector> graph, rgraph; void dfs(const int ver) { is_used[ver] = true; for (const int e : graph[ver]) { if (!is_used[e]) dfs(e); } order.emplace_back(ver); } void rdfs(const int ver, const int m) { id[ver] = m; if constexpr (IS_FULL_VER) vertices.back().emplace_back(ver); for (const int e : rgraph[ver]) { if (id[e] == -1) rdfs(e, m); } } }; int main() { int n; cin >> n; vector> graph(n); REP(i, n) { int m; cin >> m; while (m--) { int a; cin >> a; --a; graph[i].emplace_back(a); } } const StronglyConnectedComponents scc(graph); int num = 1; for (int i = scc.id[0]; ;) { int index = 0; while (index < scc.g[i].size() && scc.g[i][index] == i) ++index; if (index == scc.g[i].size()) break; i = scc.g[i][index]; ++num; } cout << (num == scc.g.size() ? "Yes\n" : "No\n"); return 0; }