結果
問題 | No.1266 7 Colors |
ユーザー |
![]() |
提出日時 | 2020-06-04 22:43:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 144 ms / 3,000 ms |
コード長 | 1,780 bytes |
コンパイル時間 | 1,768 ms |
コンパイル使用メモリ | 175,216 KB |
実行使用メモリ | 14,972 KB |
最終ジャッジ日時 | 2024-07-20 17:48:57 |
合計ジャッジ時間 | 6,535 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;#define rep(i,n,m) for(ll (i)=(n);(i)<(m);i++)#define REP(i,n) rep(i,0,n)#define en "\n"template <class T> using vec=vector<T>;template <class T> using vvec=vec<vec<T>>;class UnionFind {vector<int> data;int num;public:UnionFind(int size) : data(size, -1), num(size) { }bool unionSet(int x, int y) {x = root(x); y = root(y);if (x != y) {if (data[y] < data[x]) swap(x, y);data[x] += data[y]; data[y] = x;num--;}return x != y;}bool findSet(int x, int y) {return root(x) == root(y);}int root(int x) {return data[x] < 0 ? x : data[x] = root(data[x]);}int size(int x) {return -data[root(x)];}int numSet() {return num;}};int main(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);ll n,m,q;cin>>n>>m>>q;vec<string> col(n);vvec<int> g(n);UnionFind uni(n*7);REP(i,n){cin>>col[i];REP(j,7){if(col[i][j]=='1'&&col[i][(j+1)%7]=='1'){uni.unionSet(i*7+j,i*7+(j+1)%7);}}}REP(i,m){ll a,b;cin>>a>>b;a--;b--;g[a].push_back(b);g[b].push_back(a);REP(j,7) if(col[a][j]=='1' && col[b][j]=='1')uni.unionSet(a*7+j,b*7+j);}REP(i,q){ll t,x,y;cin>>t>>x>>y;x--;y--;if(t==1){col[x][y]='1';if(col[x][(y+6)%7]=='1') uni.unionSet(x*7+y,x*7+(y+6)%7);if(col[x][(y+1)%7]=='1') uni.unionSet(x*7+y,x*7+(y+1)%7);for(auto to:g[x]){if(col[to][y]=='1') uni.unionSet(x*7+y,to*7+y);}}else{cout<<uni.size(x*7)<<en;}}return 0;}