結果
| 問題 | No.3425 Mod K Graph Increments (Easy) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-01-11 13:51:29 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 61 ms / 2,000 ms |
| コード長 | 936 bytes |
| 記録 | |
| コンパイル時間 | 1,783 ms |
| コンパイル使用メモリ | 218,152 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-01-11 13:51:35 |
| 合計ジャッジ時間 | 2,951 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 7 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T; cin >> T;
while(T--){
int N,M,K; cin >> N >> M >> K;
vector<vector<int>> Graph(N);
for(int i=0; i<N-1; i++){
int u,v; cin >> u >> v;
u--; v--;
Graph.at(u).push_back(v);
Graph.at(v).push_back(u);
}
vector<int> B(N),A(N);
for(auto &b : B) cin >> b;
auto dfs = [&](auto dfs,int pos,int back) -> void {
long long sum = 0;
for(auto to : Graph.at(pos)){
if(to == back) continue;
dfs(dfs,to,pos);
int ope = (B.at(to)-A.at(to)+K)%K;
A.at(to) = B.at(to),sum += ope;
}
A.at(pos) = sum%K;
};
dfs(dfs,0,-1);
if(A == B) cout << "Yes\n";
else cout << "No\n";
}
}