結果
問題 | No.1266 7 Colors |
ユーザー |
![]() |
提出日時 | 2020-10-23 22:50:57 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 147 ms / 3,000 ms |
コード長 | 2,388 bytes |
コンパイル時間 | 2,491 ms |
コンパイル使用メモリ | 201,948 KB |
最終ジャッジ日時 | 2025-01-15 13:45:04 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
// #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> using namespace std; typedef long long ll; #define endl '\n' #define all(x) (x).begin(),(x).end() template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;} template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;} int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0}; long double eps = 1e-9; long double pi = acos(-1); class UnionFind{ public: //親の番号を格納する。親だった場合は-(その集合のサイズ) vector<int> parent; UnionFind(int N){ parent = vector<int>(N,-1); } int root(int A){ if(parent[A] < 0) return A; return parent[A]=root(parent[A]); } int size(int A){ return -parent[root(A)]; } bool unite(int A, int B) { A = root(A), B = root(B); if(A == B) return false; if(size(A) < size(B)) swap(A,B); parent[A] += parent[B]; parent[B] = A; return true; } bool same(int A, int B){ return root(A)==root(B); } }; vector<vector<int>> v(100010); signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); int n,m,q; cin>>n>>m>>q; int nn = n*7; UnionFind uni(nn); string s[n]; for(int i=0;i<n;i++){ cin>>s[i]; for(int j=0;j<7;j++){ if(s[i][j] == '1' && s[i][(j+6)%7] == '1'){ uni.unite(j+i*7,(j+6)%7+i*7); } } } for(int i=0;i<m;i++){ int a,b; cin>>a>>b; a--,b--; v[a].push_back(b); v[b].push_back(a); for(int j=0;j<7;j++){ if(s[a][j] == s[b][j] && s[a][j] == '1'){ uni.unite(j+a*7, j+b*7); } } } while(q--){ int t,x,y; cin>>t>>x>>y; y--; x--; if(t == 1){ s[x][y] = '1'; int ny; ny = (y+1)%7; if(s[x][ny]=='1')uni.unite(ny+x*7,y+x*7); ny = (y+6)%7; if(s[x][ny]=='1')uni.unite(ny+x*7,y+x*7); for(auto i:v[x]){ if(s[i][y] == '1')uni.unite(y+x*7,y+i*7); } } else{ cout << uni.size(0+x*7) << endl; } } }