結果

問題 No.1266 7 Colors
ユーザー firiexp
提出日時 2020-10-23 22:39:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 156 ms / 3,000 ms
コード長 2,300 bytes
コンパイル時間 1,354 ms
コンパイル使用メモリ 107,004 KB
最終ジャッジ日時 2025-01-15 13:35:05
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:68:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   68 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:78:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   78 |         scanf("%d %d %d", &t, &x, &y); x--; y--;
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

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

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
class UnionFind {
int n;
vector<int> uni;
int forest_size;
public:
explicit UnionFind(int n) : n(n), uni(static_cast<u32>(n), -1), forest_size(n) {};
int root(int a){
if (uni[a] < 0) return a;
else return (uni[a] = root(uni[a]));
}
bool unite(int a, int b) {
a = root(a);
b = root(b);
if(a == b) return false;
if(uni[a] > uni[b]) swap(a, b);
uni[a] += uni[b];
uni[b] = a;
forest_size--;
return true;
}
int size(){ return forest_size; }
int size(int i){ return -uni[root(i)]; }
bool same(int a, int b) { return root(a) == root(b); }
};
int main() {
int n, m, q;
cin >> n >> m >> q;
vector<int> C(n);
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
for (int j = 0; j < s.size(); ++j) {
if(s[j] == '1') C[i] |= (1 << j);
}
}
UnionFind uf(7*n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 7; ++j) {
if(C[i]&(1 << j) && C[i]&(1 << ((j+1)%7))){
uf.unite(i*7+j, i*7+(j+1)%7);
}
}
}
vector<vector<int>> G(n);
for (int i = 0; i < m; ++i) {
int a, b;
scanf("%d %d", &a, &b);
a--; b--;
G[a].emplace_back(b);
G[b].emplace_back(a);
for (int j = 0; j < 7; ++j) {
if(C[a]&(1 << j) && C[b]&(1 << j)) uf.unite(a*7+j, b*7+j);
}
}
while(q--){
int t, x, y;
scanf("%d %d %d", &t, &x, &y); x--; y--;
if(t == 1){
C[x] |= (1 << y);
if(C[x]&(1 << (y+1)%7)) uf.unite(x*7+y, x*7+(y+1)%7);
if(C[x]&(1 << (y+6)%7)) uf.unite(x*7+y, x*7+(y+6)%7);
for (auto &&i : G[x]) {
if(C[i]&(1 << y)) uf.unite(x*7+y, i*7+y);
}
}else {
printf("%d\n", uf.size(x*7));
}
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0