結果
問題 | No.1266 7 Colors |
ユーザー | w2w2 |
提出日時 | 2020-10-23 22:35:00 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,819 bytes |
コンパイル時間 | 2,937 ms |
コンパイル使用メモリ | 214,280 KB |
実行使用メモリ | 15,352 KB |
最終ジャッジ日時 | 2024-07-21 11:24:06 |
合計ジャッジ時間 | 6,228 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 75 ms
15,352 KB |
testcase_19 | AC | 72 ms
14,552 KB |
testcase_20 | AC | 73 ms
14,520 KB |
testcase_21 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <algorithm> #include <cassert> #include <vector> namespace atcoder { // Implement (union by size) + (path compression) // Reference: // Zvi Galil and Giuseppe F. Italiano, // Data structures and algorithms for disjoint set union problems struct dsu { public: dsu() : _n(0) {} dsu(int n) : _n(n), parent_or_size(n, -1) {} int merge(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); int x = leader(a), y = leader(b); if (x == y) return x; if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y); parent_or_size[x] += parent_or_size[y]; parent_or_size[y] = x; return x; } bool same(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); return leader(a) == leader(b); } int leader(int a) { assert(0 <= a && a < _n); if (parent_or_size[a] < 0) return a; return parent_or_size[a] = leader(parent_or_size[a]); } int size(int a) { assert(0 <= a && a < _n); return -parent_or_size[leader(a)]; } std::vector<std::vector<int>> groups() { std::vector<int> leader_buf(_n), group_size(_n); for (int i = 0; i < _n; i++) { leader_buf[i] = leader(i); group_size[leader_buf[i]]++; } std::vector<std::vector<int>> result(_n); for (int i = 0; i < _n; i++) { result[i].reserve(group_size[i]); } for (int i = 0; i < _n; i++) { result[leader_buf[i]].push_back(i); } result.erase( std::remove_if(result.begin(), result.end(), [&](const std::vector<int>& v) { return v.empty(); }), result.end()); return result; } private: int _n; // root node: -1 * component size // otherwise: parent std::vector<int> parent_or_size; }; } // namespace atcoder using namespace atcoder; using ll= long long; using ld= long double; using pll= pair<ll, ll>; using vi= vector<int>; using vl= vector<ll>; using vd= vector<ld>; using vs= vector<string>; using vb= vector<bool>; using vpll= vector<pll>; using vvi= vector<vi>; using vvl= vector<vl>; using vvd= vector<vd>; using vvs= vector<vs>; using vvb= vector<vb>; using vvpll= vector<vpll>; // using mint= modint1000000007; // using mint = modint998244353; constexpr ll mod= 1e9 + 7; // constexpr ll mod= 998244353; #define ALL(x) (x).begin(), (x).end() #define _overload(_1, _2, _3, name, ...) name #define REPBASE(i, a, b) for(ll(i)= (a); (i) < (b); (i)++) #define RREPBASE(i, a, b) for(ll(i)= (a); (i) >= (b); (i)--) #define REPB(i, n) REPBASE(i, 0, n) #define REPS(i, n) REPBASE(i, 1, n + 1) #define RREP(i, n) RREPBASE(i, n - 1, 0) #define RREPS(i, n) RREPBASE(i, n, 1) #define REP(...) _overload(__VA_ARGS__, REPBASE, REPB)(__VA_ARGS__) #define EACH(x, c) for(auto &x : c) #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define UNIQUE(v) v.erase(unique(ALL(v)), v.end()) #define YES(n) ((n) ? "YES" : "NO") #define Yes(n) ((n) ? "Yes" : "No") #define yes(n) ((n) ? "yes" : "no") #define SZ(x) ((ll)(x).size()) #define BIT(n) (1LL << (n)) template <class T> inline bool chmax(T &a, const T &b) { if(a < b) { a= b; return 1; } return 0; } template <class T> inline bool chmin(T &a, const T &b) { if(b < a) { a= b; return 1; } return 0; } signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12); ll N,M,Q; cin >> N >> M >> Q; vs C(N); REP(i,N)cin >> C[i]; dsu D(N*7); REP(i,N){ REP(l,7){ if(C[i][l] == '1' && C[i][(l+1) % 7] == '1'){ D.merge(i*7+l,i*7+(l+1)%7); } } } vvl G(N,vl(0)); REP(i,M){ ll pq,qr; cin >> pq >> qr; pq--;qr--; G[pq].eb(qr); G[qr].eb(pq); REP(l,7){ if(C[pq][l] == '1' && C[qr][l] == '1'){ D.merge(pq*7+l,qr*7+l); } } } REP(i,Q){ ll Type; cin >> Type; if(Type == 1){ ll x,y; cin >> x >> y; x--;y--; C[x][y] == '1'; if(C[x][(y+1) % 7] == '1'){ D.merge(x*7+y,x*7+(y+1)%7); } if(C[x][(y+6) % 7] == '1'){ D.merge(x*7+y,x*7+(y+6)%7); } EACH(p,G[x]){ if(C[p][y] == '1'){ D.merge(x*7+y,p*7+y); } } }else{ ll x,y; cin >> x >> y; x--; cout << D.size(7*x) << "\n"; } } }