Submission #44544823
Source Code Expand
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define _overload3(_1,_2,_3,name,...) name
#define _REP(i,n) REPI(i,0,n)
#define REPI(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,REPI,_REP,)(__VA_ARGS__)
#define _RREP(i,n) RREPI(i,n,0)
#define RREPI(i,a,b) for(int i=int(a);i>=int(b);--i)
#define RREP(...) _overload3(__VA_ARGS__,RREPI,_RREP,)(__VA_ARGS__)
#define ALL(a) (a).begin(),(a).end()
#define ALLR(a) (a).rbegin(),(a).rend()
typedef long long ll;
const int INF32 = 1001001001;
const long long INF64 = 1001001001001001001;
struct Init { Init() { ios::sync_with_stdio(0); cin.tie(0); cout << setprecision(15); }} init;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template<class T> T gcd(T x, T y){ return (x % y) ? gcd(y, x % y) : y; }
template<class T> T lcm(T x, T y){ return x / gcd(x, y) * y; }
template<class T, class... Ts> void output(const T& a, const Ts&... b) { cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
template<class T> void output(vector<T> v) { for (auto u : v) cout << u << ' '; cout << '\n'; };
void yesno(bool is_ok) { cout << (is_ok ? "yes" : "no") << '\n'; }
void YesNo(bool is_ok) { cout << (is_ok ? "Yes" : "No") << '\n'; }
void YESNO(bool is_ok) { cout << (is_ok ? "YES" : "NO") << '\n'; }
// clang-format on
int main() {
int n, m;
cin >> n >> m;
vector<int> a(n), b(n);
REP(i, m) cin >> a[i] >> b[i], --a[i], --b[i];
int q;
cin >> q;
vector<tuple<int, int, int>> queries(q);
vector<bool> stop(n, false);
REP(i, q) {
int t;
cin >> t;
if (t == 1) {
int x;
cin >> x;
--x;
queries[i] = {t, x, -1};
stop[x] = true;
} else {
int u, v;
cin >> u >> v;
--u, --v;
queries[i] = {t, u, v};
}
}
reverse(ALL(queries));
dsu uf(n);
REP(i, m) {
if (stop[i]) continue;
if (uf.same(a[i], b[i])) continue;
uf.merge(a[i], b[i]);
}
vector<bool> ans;
for (auto [t, x, y] : queries) {
if (t == 1) {
if (!uf.same(a[x], b[x])) {
uf.merge(a[x], b[x]);
}
} else {
ans.push_back(uf.same(x, y));
}
}
reverse(ALL(ans));
for (bool v : ans) {
YesNo(v);
}
}
Submission Info
| Submission Time |
|
| Task |
B66 - Typhoon |
| User |
noko206 |
| Language |
C++ (GCC 9.2.1) |
| Score |
1000 |
| Code Size |
2686 Byte |
| Status |
AC |
| Exec Time |
49 ms |
| Memory |
5576 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
1000 / 1000 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample00.txt, sample01.txt, sample02.txt |
| All |
00.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, sample00.txt, sample01.txt, sample02.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00.txt |
AC |
49 ms |
5536 KiB |
| 01.txt |
AC |
36 ms |
5460 KiB |
| 02.txt |
AC |
36 ms |
5576 KiB |
| 03.txt |
AC |
37 ms |
5512 KiB |
| 04.txt |
AC |
4 ms |
3492 KiB |
| 05.txt |
AC |
26 ms |
4780 KiB |
| 06.txt |
AC |
20 ms |
4520 KiB |
| 07.txt |
AC |
47 ms |
5540 KiB |
| sample00.txt |
AC |
3 ms |
3608 KiB |
| sample01.txt |
AC |
2 ms |
3556 KiB |
| sample02.txt |
AC |
2 ms |
3576 KiB |