結果

問題 No.3425 Mod K Graph Increments (Easy)
コンテスト
ユーザー umimel
提出日時 2026-01-13 02:51:08
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,640 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,882 ms
コンパイル使用メモリ 192,788 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2026-01-13 02:51:11
合計ジャッジ時間 3,062 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const ll MOD1000000007 = 1000000007;
const ll MOD998244353 = 998244353;
const ll MOD[3] = {999727999, 1070777777, 1000000007};
const ll LINF = 1LL << 60LL;
const int IINF = (1 << 30) - 1;


void solve(){
    int n, m; cin >> n >> m;
    ll k; cin >> k;
    vector<vector<int>> G(n);
    for(int i=0; i<m; i++){
        int u, v; cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    vector<ll> b(n); for(int i=0; i<n; i++) cin >> b[i];
    if(k%2 == 0){
        ll sumB = 0LL; for(int i=0; i<n; i++) sumB += b[i];
        if(sumB%2 == 1){
            cout << "No\n";
            return;
        }
    }
    
    vector<int> c(n, -1);
    bool is_bipartite = true;
    function<void(int)> bipartite_coloring = [&](int v){
        for(int to : G[v]){
            if(c[to] == -1){
                c[to] = 1 - c[v];
                bipartite_coloring(to);
            }else if(c[to] == c[v]){
                is_bipartite = false;
            }
        }
    };
    c[0] = 0; bipartite_coloring(0);
    if(!is_bipartite){
        cout << "Yes\n";
        return;
    }

    vector<ll> sum(2, 0LL);
    for(int i=0; i<n; i++) sum[c[i]] += b[i];
    if(sum[0]%k == sum[1]%k) cout << "Yes\n";
    else cout << "No\n";
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int T=1;
    cin >> T;
    while(T--) solve();
}
0