結果
問題 | No.1502 Many Simple Additions |
ユーザー | kwm_t |
提出日時 | 2021-05-13 09:37:56 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,239 bytes |
コンパイル時間 | 3,938 ms |
コンパイル使用メモリ | 233,584 KB |
実行使用メモリ | 17,408 KB |
最終ジャッジ日時 | 2024-09-24 23:12:15 |
合計ジャッジ時間 | 6,854 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
8,192 KB |
testcase_01 | AC | 4 ms
8,192 KB |
testcase_02 | AC | 4 ms
8,192 KB |
testcase_03 | AC | 4 ms
8,192 KB |
testcase_04 | AC | 4 ms
8,192 KB |
testcase_05 | AC | 4 ms
8,064 KB |
testcase_06 | AC | 4 ms
8,192 KB |
testcase_07 | AC | 4 ms
8,192 KB |
testcase_08 | AC | 4 ms
8,128 KB |
testcase_09 | AC | 4 ms
8,064 KB |
testcase_10 | AC | 4 ms
8,192 KB |
testcase_11 | WA | - |
testcase_12 | AC | 4 ms
8,192 KB |
testcase_13 | AC | 4 ms
8,320 KB |
testcase_14 | AC | 4 ms
8,136 KB |
testcase_15 | AC | 4 ms
8,064 KB |
testcase_16 | AC | 3 ms
8,320 KB |
testcase_17 | AC | 4 ms
8,192 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 4 ms
8,320 KB |
testcase_21 | AC | 3 ms
8,320 KB |
testcase_22 | AC | 4 ms
8,064 KB |
testcase_23 | WA | - |
testcase_24 | AC | 5 ms
8,320 KB |
testcase_25 | AC | 4 ms
8,064 KB |
testcase_26 | AC | 4 ms
8,320 KB |
testcase_27 | AC | 46 ms
14,592 KB |
testcase_28 | AC | 48 ms
14,720 KB |
testcase_29 | AC | 7 ms
9,984 KB |
testcase_30 | WA | - |
testcase_31 | AC | 66 ms
17,152 KB |
testcase_32 | AC | 67 ms
17,408 KB |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | AC | 35 ms
11,136 KB |
testcase_37 | AC | 35 ms
11,008 KB |
testcase_38 | AC | 41 ms
12,416 KB |
testcase_39 | AC | 27 ms
10,368 KB |
testcase_40 | AC | 15 ms
10,240 KB |
testcase_41 | AC | 6 ms
8,960 KB |
testcase_42 | AC | 51 ms
15,232 KB |
testcase_43 | AC | 4 ms
8,192 KB |
ソースコード
#include "bits/stdc++.h" #include "atcoder/all" using namespace std; using namespace atcoder; using mint = modint1000000007; const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; //const long long LINF = 1e18; //const bool debug = false; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" #define P pair<int,int> template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } struct Edge { int to, cost; Edge(int _to, int _cost) :to(_to), cost(_cost) {} }; vector<Edge>g[200005]; long long a[200005]; long long b[200005]; vector<int>w; bool ng; long long val; void dfs(int v, int p = -1) { w.push_back(v); for (Edge e : g[v]) { //if (p == e.to) continue; if (0 == a[e.to]) { a[e.to] = -a[v]; b[e.to] = e.cost - b[v]; dfs(e.to, v); } else if (a[v] != a[e.to]) { if (e.cost != b[v] + b[e.to]) { ng = true; break; } } else { if (-1 == val) { if (0 != (e.cost - b[v] - b[e.to]) % 2) { ng = true; break; } int nval = (e.cost - b[v] - b[e.to]) / 2; if (nval <= 0) { ng = true; break; } val = nval; } else { int s = a[v] * val + b[v]; int t = a[e.to] * val + b[e.to]; if (e.cost != s + t) { ng = true; break; } } } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, k; cin >> n >> m >> k; vector<int>x(m), y(m), z(m); dsu uf(n); rep(i, m) { int x, y, z; cin >> x >> y >> z; x--; y--; g[x].emplace_back(y, z); g[y].emplace_back(x, z); } mint c1 = 1, c2 = 1; rep(i, n) { if (0 != a[i]) continue; a[i] = 1; b[i] = 0; w.clear(); val = -1; dfs(i); if (ng) { cout << 0 << endl; return 0; } if (-1 == val) { { long long l = 1; long long r = k; rep(j, w.size()) { if (1 == a[w[j]]) { //0 < x + b[] <= k // -b[] < x <= k-x chmax(l, 1 - b[w[j]]); chmin(r, k - b[w[j]]); } else { //0 < -x+b[] <= k // b[]-k <= x < b[] chmax(l, b[w[j]] - k); chmin(r, b[w[j]] - 1); } } c1 *= max(0LL, r - l + 1); } { long long l = 1; long long r = k - 1; rep(j, w.size()) { if (1 == a[w[j]]) { //0 < x + b[] <= k - 1 // -b[] < x <= k - 1 -x chmax(l, 1 - b[w[j]]); chmin(r, (k - 1) - b[w[j]]); } else { //0 < -x+b[] <= k - 1 // b[]-(k - 1) <= x < b[] chmax(l, b[w[j]] - (k - 1)); chmin(r, b[w[j]] - 1); } } c2 *= max(0LL, r - l + 1); } } else { rep(j, w.size()) { long long x = a[w[j]] * val + b[w[j]]; if (x <= 0) { c1 = 0; c2 = 0; } else if (x == k) { c2 = 0; } else if (x > k) { c1 = 0; c2 = 0; } } } } cout << (c1 - c2).val() << endl; return 0; }