結果
| 問題 | No.3425 Mod K Graph Increments (Easy) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-15 06:46:23 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 101 ms / 2,000 ms |
| + 329µs | |
| コード長 | 757 bytes |
| 記録 | |
| コンパイル時間 | 2,962 ms |
| コンパイル使用メモリ | 184,496 KB |
| 実行使用メモリ | 9,800 KB |
| 最終ジャッジ日時 | 2026-10-15 06:46:31 |
| 合計ジャッジ時間 | 5,305 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 7 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
void solve(){
int n, m, k; cin >> n >> m >> k;
vector<vector<int>> to(n);
for(int i=0; i<m; i++){
int u, v; cin >> u >> v; u--, v--;
to[u].push_back(v); swap(u, v);
to[u].push_back(v);
}
vector<int> b(n), a(n);
for(auto&x:b) cin >> x;
auto dfs=[&](auto dfs, int now, int par=-1)->void {
ll add=0;
for(auto p:to[now])if(p!=par){
dfs(dfs, p, now);
ll cost=(a[p]<=b[p]?b[p]-a[p]:b[p]+k-a[p]);
a[p]=(a[p]+cost)%k;
add+=cost, add%=k;
}
a[now]=(a[now]+add)%k;
};
dfs(dfs, 0);
cout << (a[0]==b[0]?"Yes":"No") << '\n';
}
int main(void){
int t; cin >> t;
while(t--) solve();
return 0;
}