結果

問題 No.1266 7 Colors
ユーザー mtsd
提出日時 2020-10-23 22:22:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 354 ms / 3,000 ms
コード長 2,864 bytes
コンパイル時間 1,542 ms
コンパイル使用メモリ 126,904 KB
実行使用メモリ 20,416 KB
最終ジャッジ日時 2024-07-21 11:02:30
合計ジャッジ時間 8,664 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
template<class T> inline bool chmax(T &a, T b){
if(a<b){
a = b;
return true;
}
return false;
}
template<class T> inline bool chmin(T &a, T b){
if(a>b){
a = b;
return true;
}
return false;
}
class UnionFind {
private:
int sz;
vector<int> par, size_,res;
public:
UnionFind(){}
UnionFind(int node_size) : sz(node_size), par(sz), size_(sz, 1),res(sz,0){
iota(par.begin(), par.end(), 0);
}
int find(int x){
if(par[x] == x) return x;
else return par[x] = find(par[x]);
}
void unite(int x,int y){
x = find(x), y = find(y);
if(x == y) return;
if(size_[x] < size_[y]) swap(x,y);
par[y] = x;
size_[x] += size_[y];
}
int size(int x){
x = find(x);
return size_[x];
}
bool same(int x,int y){
return find(x) == find(y);
}
};
vector<vector<int> > g;
int main(){
int n,m,q;
cin >> n >> m >> q;
UnionFind uf(n*7);
vector<string> s(n);
rep(i,n){
cin >> s[i];
rep(j,7){
if(s[i][j]=='1'&&s[i][(j+1)%7]=='1'){
uf.unite(7*i+j,7*i+(j+1)%7);
}
}
}
g.resize(n);
rep(i,m){
int a,b;
cin >> a >> b;
a--;b--;
g[a].push_back(b);
g[b].push_back(a);
rep(j,7){
if(s[a][j]=='1'&&s[b][j]=='1'){
uf.unite(7*a+j,7*b+j);
}
}
}
rep(i,q){
int c,a,b;
cin >> c >> a >> b;
if(c==1){
a--;b--;
s[a][b] = '1';
if(s[a][(b+6)%7]=='1'){
uf.unite(7*a+(b+6)%7,7*a+b);
}
if(s[a][(b+1)%7]=='1'){
uf.unite(7*a+(b+1)%7,7*a+b);
}
for(auto& x:g[a]){
if(s[x][b]=='1'){
uf.unite(7*a+b,7*x+b);
}
}
}else{
a--;
cout << uf.size(a*7) << "\n";
}
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0