結果

問題 No.1290 Addition and Subtraction Operation
ユーザー SSRSSSRS
提出日時 2020-11-13 22:43:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 1,063 bytes
コンパイル時間 1,823 ms
コンパイル使用メモリ 177,292 KB
実行使用メモリ 10,316 KB
最終ジャッジ日時 2023-09-30 03:44:20
合計ジャッジ時間 6,739 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 37 ms
4,920 KB
testcase_43 AC 37 ms
5,032 KB
testcase_44 AC 35 ms
5,028 KB
testcase_45 AC 38 ms
4,896 KB
testcase_46 AC 37 ms
4,888 KB
testcase_47 AC 36 ms
4,916 KB
testcase_48 AC 36 ms
4,852 KB
testcase_49 AC 35 ms
4,904 KB
testcase_50 AC 36 ms
4,912 KB
testcase_51 AC 35 ms
4,844 KB
testcase_52 AC 36 ms
5,164 KB
testcase_53 AC 37 ms
4,884 KB
testcase_54 AC 37 ms
4,888 KB
testcase_55 AC 36 ms
4,860 KB
testcase_56 AC 36 ms
4,892 KB
testcase_57 AC 33 ms
8,204 KB
testcase_58 AC 45 ms
8,596 KB
testcase_59 AC 34 ms
7,880 KB
testcase_60 AC 78 ms
10,316 KB
testcase_61 AC 61 ms
9,456 KB
testcase_62 AC 65 ms
9,712 KB
testcase_63 AC 42 ms
8,580 KB
testcase_64 AC 19 ms
6,740 KB
testcase_65 AC 26 ms
7,424 KB
testcase_66 AC 49 ms
8,988 KB
testcase_67 AC 81 ms
10,276 KB
testcase_68 AC 62 ms
9,692 KB
testcase_69 AC 42 ms
8,724 KB
testcase_70 AC 40 ms
8,404 KB
testcase_71 AC 47 ms
8,880 KB
testcase_72 AC 27 ms
7,520 KB
testcase_73 AC 55 ms
9,080 KB
testcase_74 AC 18 ms
6,472 KB
testcase_75 AC 25 ms
7,416 KB
testcase_76 AC 41 ms
8,732 KB
testcase_77 AC 85 ms
9,648 KB
testcase_78 AC 81 ms
9,516 KB
testcase_79 AC 60 ms
8,292 KB
testcase_80 AC 96 ms
9,920 KB
testcase_81 AC 92 ms
9,904 KB
testcase_82 AC 65 ms
8,988 KB
testcase_83 AC 92 ms
10,052 KB
testcase_84 AC 81 ms
9,652 KB
testcase_85 AC 46 ms
7,840 KB
testcase_86 AC 39 ms
6,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> B(N);
  for (int i = 0; i < N; i++){
    cin >> B[i];
    if (i % 2 == 0){
      B[i] *= -1;
    }
  }
  vector<int> L(M), R(M);
  for (int i = 0; i < M; i++){
    cin >> L[i] >> R[i];
    L[i]--;
  }
  vector<long long> A(N + 1);
  A[0] = B[0];
  for (int i = 1; i < N; i++){
    A[i] = B[i] - B[i - 1];
  }
  A[N] = -B[N - 1];
  vector<vector<int>> E(N + 1);
  for (int i = 0; i < M; i++){
    E[L[i]].push_back(R[i]);
    E[R[i]].push_back(L[i]);
  }
  vector<bool> used(N + 1, false);
  for (int i = 0; i <= N; i++){
    if (!used[i]){
      used[i] = true;
      long long sum = 0;
      queue<int> Q;
      Q.push(i);
      while (!Q.empty()){
        int v = Q.front();
        Q.pop();
        sum += A[v];
        for (int w : E[v]){
          if (!used[w]){
            used[w] = true;
            Q.push(w);
          }
        }
      }
      if (sum != 0){
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
}
0