結果
| 問題 |
No.1266 7 Colors
|
| コンテスト | |
| ユーザー |
auaua
|
| 提出日時 | 2020-10-23 22:38:05 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 220 ms / 3,000 ms |
| コード長 | 2,355 bytes |
| コンパイル時間 | 2,018 ms |
| コンパイル使用メモリ | 175,252 KB |
| 実行使用メモリ | 18,088 KB |
| 最終ジャッジ日時 | 2024-07-21 11:28:08 |
| 合計ジャッジ時間 | 6,339 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll INF=1e9+7;
const ll inf=INF*INF;
const ll MOD=1e9+7;
const ll mod=MOD;
const int MAX=200010;
//Union-Find木
struct UnionFind {
vector< int > data;
UnionFind() = default;
explicit UnionFind(size_t sz) : data(sz, -1) {}
bool unite(int x, int y) {
x = find(x), y = find(y);
if(x == y) return false;
if(data[x] > data[y]) swap(x, y);
data[x] += data[y];
data[y] = x;
return true;
}
int find(int k) {
if(data[k] < 0) return (k);
return data[k] = find(data[k]);
}
int size(int k) {
return -data[find(k)];
}
bool same(int x, int y) {
return find(x) == find(y);
}
};
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n,m,q;cin>>n>>m>>q;
UnionFind uf(n*7);
vector<string>s(n);
rep(i,n)cin>>s[i];
vector<vector<ll> >G(n);
rep(i,m){
ll u,v;cin>>u>>v;
u--;v--;
G[u].pb(v);
G[v].pb(u);
rep(col,7){
if(s[u][col]=='1'&&s[v][col]=='1')uf.unite(7*u+col,7*v+col);
}
}
rep(i,n){
rep(col,7){
if(s[i][col]=='1'&&s[i][(col+1)%7]=='1'){
uf.unite(i*7+col,i*7+(col+1)%7);
}
}
}
while(q--){
ll t;cin>>t;
if(t==1){
ll x,y;cin>>x>>y;
x--;
y--;
s[x][y]='1';
if(s[x][(y+6)%7]=='1'){
uf.unite(x*7+y,x*7+(y+6)%7);
}
if(s[x][(y+1)%7]=='1'){
uf.unite(x*7+y,x*7+(y+1)%7);
}
for(auto e:G[x]){
if(s[e][y]=='1'){
uf.unite(x*7+y,e*7+y);
}
}
}else{
ll x,y;cin>>x>>y;
x--;y--;
cout<<uf.size(x*7)<<endl;
}
}
}
auaua