Submission #992679
Source Code Expand
#include<iostream> #include<vector> #include<string> #include<algorithm> #include<math.h> #include<map> #include<iterator> #include<set> #include<queue> #define rep(i,n) for(int i = 0; i < n; i++) using namespace std; int main(){ int n,m; cin >> n >> m; vector<set<int>> edges(m); vector<bool> communicatable(m, true); int first; rep(i,n){ vector<int> input; int K; cin >> K; rep(j,K){ int temp; cin >> temp; input.push_back(temp - 1); } sort(input.begin(), input.end()); first = input[0]; rep(j, input.size()){ communicatable[input[j]] = false; if(j == 0) continue; edges[first].insert(input[j]); edges[input[j]].insert(first); } } queue<int> q; q.push(first); communicatable[first] = true; while(!q.empty()){ int nowelem = q.front(); q.pop(); for(auto itr = edges[nowelem].begin(); itr != edges[nowelem].end(); itr++){ int src = *itr; if(!communicatable[src]){ communicatable[src] = true; q.push(src); } } } bool ans = true; rep(i,m){ if(!communicatable[i]){ ans = false; break; } } if(ans) cout << "YES" << endl; else cout << "NO" << endl; }
Submission Info
Submission Time | |
---|---|
Task | C - Interpretation |
User | dolicas |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 1205 Byte |
Status | AC |
Exec Time | 72 ms |
Memory | 13952 KB |
Judge Result
Set Name | sample | dataset1 | dataset2 | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 200 / 200 | 200 / 200 | ||||||
Status |
|
|
|
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 | 384 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 | 384 KB |
01-07.txt | AC | 3 ms | 256 KB |
01-08.txt | AC | 3 ms | 384 KB |
01-09.txt | AC | 3 ms | 256 KB |
01-10.txt | AC | 3 ms | 256 KB |
02-01.txt | AC | 72 ms | 13952 KB |
02-02.txt | AC | 44 ms | 512 KB |
02-03.txt | AC | 70 ms | 11136 KB |
02-04.txt | AC | 67 ms | 8960 KB |
02-05.txt | AC | 54 ms | 2560 KB |
02-06.txt | AC | 65 ms | 8960 KB |
02-07.txt | AC | 49 ms | 1664 KB |
02-08.txt | AC | 37 ms | 256 KB |
02-09.txt | AC | 56 ms | 4992 KB |
02-10.txt | AC | 62 ms | 7484 KB |
02-11.txt | AC | 62 ms | 7484 KB |
02-12.txt | AC | 57 ms | 6912 KB |
02-13.txt | AC | 56 ms | 6784 KB |
sample-01.txt | AC | 3 ms | 256 KB |
sample-02.txt | AC | 3 ms | 256 KB |