Submission #25506673
Source Code Expand
#include <deque>
#include <queue>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define PII pair <int, int>
#define MP(x,y) make_pair (x, y)
const int Maxn = 2 * 1e5;
int n, m;
deque <int> v[Maxn + 5];
int vis[Maxn + 5];
int main () {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int num; cin >> num;
for (int j = 1; j <= num; j++)
{ int x; cin >> x; v[i].push_back (x); }
}
queue <PII> q;
for (int i = 1; i <= m; i++) {
if (vis[v[i][0]]) {
q.push (MP (vis[v[i][0]], i));
continue;
}
vis[v[i][0]] = i;
}
while (q.size ()) {
PII tmp = q.front (); q.pop ();
v[tmp.first].pop_front ();
v[tmp.second].pop_front ();
if (v[tmp.first].size () && vis[v[tmp.first][0]]) {
q.push (MP (vis[v[tmp.first][0]], tmp.first));
}
else if (v[tmp.first].size ()) {
vis[v[tmp.first][0]] = tmp.first;
}
if (v[tmp.second].size () && vis[v[tmp.second][0]]) {
q.push (MP (vis[v[tmp.second][0]], tmp.second));
}
else if (v[tmp.second].size ()) {
vis[v[tmp.second][0]] = tmp.second;
}
}
int res = 0;
for (int i = 1; i <= m; i++) {
res += v[i].size ();
}
if (res) cout << "No";
else cout << "Yes";
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Pair of Balls |
| User | C2022lihan |
| Language | C++ (Clang 10.0.0) |
| Score | 400 |
| Code Size | 1258 Byte |
| Status | AC |
| Exec Time | 812 ms |
| Memory | 822604 KiB |
Judge Result
| Set Name | Sample | All | after_contest | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | 0 / 0 | ||||||
| Status |
|
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt |
| All | example0.txt, example1.txt, 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt |
| after_contest | after_contest0.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 17 ms | 12256 KiB |
| 001.txt | AC | 12 ms | 12252 KiB |
| 002.txt | AC | 711 ms | 713288 KiB |
| 003.txt | AC | 216 ms | 13952 KiB |
| 004.txt | AC | 707 ms | 713944 KiB |
| 005.txt | AC | 104 ms | 13392 KiB |
| 006.txt | AC | 678 ms | 698380 KiB |
| 007.txt | AC | 175 ms | 13748 KiB |
| 008.txt | AC | 704 ms | 713916 KiB |
| 009.txt | AC | 224 ms | 14744 KiB |
| 010.txt | AC | 701 ms | 713556 KiB |
| 011.txt | AC | 224 ms | 14952 KiB |
| 012.txt | AC | 700 ms | 713712 KiB |
| 013.txt | AC | 152 ms | 14024 KiB |
| 014.txt | AC | 709 ms | 713776 KiB |
| 015.txt | AC | 82 ms | 12924 KiB |
| 016.txt | AC | 812 ms | 822600 KiB |
| 017.txt | AC | 811 ms | 822524 KiB |
| 018.txt | AC | 219 ms | 14496 KiB |
| 019.txt | AC | 221 ms | 14428 KiB |
| 020.txt | AC | 225 ms | 14968 KiB |
| 021.txt | AC | 808 ms | 822584 KiB |
| 022.txt | AC | 664 ms | 612992 KiB |
| 023.txt | AC | 774 ms | 769180 KiB |
| 024.txt | AC | 640 ms | 822604 KiB |
| after_contest0.txt | AC | 222 ms | 14452 KiB |
| example0.txt | AC | 15 ms | 12252 KiB |
| example1.txt | AC | 10 ms | 12400 KiB |