結果
| 問題 | 
                            No.1290 Addition and Subtraction Operation
                             | 
                    
| コンテスト | |
| ユーザー | 
                             noshi91
                         | 
                    
| 提出日時 | 2020-11-13 22:04:16 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,287 bytes | 
| コンパイル時間 | 784 ms | 
| コンパイル使用メモリ | 76,236 KB | 
| 最終ジャッジ日時 | 2025-01-15 22:59:06 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 73 WA * 12 | 
ソースコード
#include <iostream>
#include <vector>
#include <cstdint>
#include <cstddef>
#include <numeric>
using usize = std::size_t;
using i64 = std::int64_t;
struct with_sum {
    std::vector<i64> w;
    std::vector<usize> p;
    with_sum(std::vector<i64> w_): w(w_), p(w_.size()) {
        std::iota(p.begin(), p.end(), 0);
    }
    usize find(usize x) {
        if (p[x] == x) {
            return x;
        } else {
            return p[x] = find(p[x]);
        }
    }
    void unite(usize x, usize y) {
        x = find(x);
        y = find(y);
        p[y] = x;
        w[x] += w[y];
    }
};
int main() {
    usize n, m;
    std::cin >> n >> m;
    std::vector<i64> b(n + 1, 0);
    for (usize i = 0; i != n; i += 1) {
        i64 t;
        std::cin >> t;
        b[i] += t;
        b[i + 1] += t;
    }
    for (usize i = 0; i < n + 1; i += 2) {
        b[i] = -b[i];
    }
    with_sum uf(b);
    for (usize i = 0; i != m; i += 1) {
        usize l, r;
        std::cin >> l >> r;
        l -= 1;
        uf.unite(l, r);
    }
    for (usize i = 0; i != n + 1; i += 1) {
        if (uf.find(i) != i) {
            continue;
        }
        if(uf.w[i] != 0) {
            std::cout << "NO\n";
            return 0;
        }
    }
    std::cout << "YES\n";
    return 0;
}
            
            
            
        
            
noshi91