結果

問題 No.3425 Mod K Graph Increments (Easy)
コンテスト
ユーザー NaH54i
提出日時 2026-01-11 14:14:19
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 1,595 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,841 ms
コンパイル使用メモリ 349,932 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-01-11 14:14:24
合計ジャッジ時間 5,603 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other WA * 5 RE * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
次のファイルから読み込み:  /usr/local/gcc-15/include/c++/15.2.0/bits/stl_iterator.h:78,
         次から読み込み:  /usr/local/gcc-15/include/c++/15.2.0/bits/stl_algobase.h:67,
         次から読み込み:  /usr/local/gcc-15/include/c++/15.2.0/algorithm:62,
         次から読み込み:  /usr/local/gcc-15/include/c++/15.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:53,
         次から読み込み:  main.cpp:1:
In function ‘constexpr _Tp* std::construct_at(_Tp*, _Args&& ...) [with _Tp = long long int; _Args = {const long long int&}]’,
    inlined from ‘static constexpr void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = long long int; _Args = {const long long int&}; _Tp = long long int]’ at /usr/local/gcc-15/include/c++/15.2.0/bits/alloc_traits.h:676:21,
    inlined from ‘void std::deque<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]’ at /usr/local/gcc-15/include/c++/15.2.0/bits/stl_deque.h:1610:30,
    inlined from ‘void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = long long int; _Sequence = std::deque<long long int, std::allocator<long long int> >]’ at /usr/local/gcc-15/include/c++/15.2.0/bits/stl_queue.h:313:20,
    inlined from ‘int main()’ at main.cpp:44:17:
/usr/local/gcc-15/include/c++/15.2.0/bits/stl_construct.h:110:16: 警告: ‘st’ may be used uninitialized [-Wmaybe-uninitialized]
  110 |         return ::new(__loc) _Tp(std::forward<_Args>(__args)...);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:34:12: 備考: ‘st’ はここで定義されています
   34 |         ll st;
      |            ^~

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
using ld = long double;
//using mint = modint998244353;
int main(){
    ll T;
    cin >> T;
    while(T--){
        ll n,m,k;
        cin >> n >> m >> k;

        vector<vector<ll>> pass(n,vector<ll>(0));
        vector<pair<ll,ll>> way(0);
        //unordered_map<ll,ll> cost;
        ll u,v;

        for(ll i = 0; i < m; i++){
            cin >> u >> v;
            u--;
            v--;
            pass[u].push_back(v);
            pass[v].push_back(u);
        }

        vector<ll> b(n,0);
        
        for(ll i = 0; i < n; i++){
            cin >> b[i];
        }

        ll st;
        for(ll i = 0; i < n; i++){
            if(pass[i].size() == 1){
                st = i;
                break;
            }
        }

        bool ans = 1;
        queue<ll> bfs;
        bfs.push(st);
        vector<bool> come(n,0);
        come[st] = 1;


        while(!bfs.empty()){
            ll x = bfs.front();
            bfs.pop();

            if(pass[x].size() == 1 && x != st){
                if(b[x] != 0){
                    ans = 0;
                    break;
                }
            }

            for(ll i : pass[x]){
                if(come[i])continue;
                come[i] = 1;

                b[i] += k;
                b[i] -= b[x];
                b[i] %= k;
                b[x] = 0;

                bfs.push(i);
            }
        }

        if(ans)cout << "Yes" << '\n';
        else cout << "No" << '\n';

    }



    return 0;
}
0