結果
問題 | No.1502 Many Simple Additions |
ユーザー | PCTprobability |
提出日時 | 2021-05-07 22:20:56 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 4,664 bytes |
コンパイル時間 | 2,058 ms |
コンパイル使用メモリ | 157,480 KB |
実行使用メモリ | 31,636 KB |
最終ジャッジ日時 | 2024-09-15 10:23:32 |
合計ジャッジ時間 | 10,253 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | AC | 155 ms
14,592 KB |
testcase_28 | AC | 153 ms
15,156 KB |
testcase_29 | RE | - |
testcase_30 | AC | 285 ms
31,636 KB |
testcase_31 | AC | 287 ms
31,504 KB |
testcase_32 | AC | 289 ms
31,616 KB |
testcase_33 | AC | 193 ms
20,484 KB |
testcase_34 | AC | 207 ms
21,360 KB |
testcase_35 | AC | 196 ms
20,668 KB |
testcase_36 | WA | - |
testcase_37 | AC | 112 ms
14,812 KB |
testcase_38 | AC | 142 ms
17,548 KB |
testcase_39 | AC | 83 ms
11,596 KB |
testcase_40 | AC | 48 ms
7,936 KB |
testcase_41 | RE | - |
testcase_42 | AC | 215 ms
26,948 KB |
testcase_43 | RE | - |
ソースコード
#include <limits.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <algorithm> #include <cassert> #include <cfloat> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; //#include <atcoder/all> // using namespace atcoder; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i) #define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i) #define Sort(v) sort(v.begin(), v.end()) #define rSort(v) sort(v.rbegin(), v.rend()) #define Reverse(v) reverse(v.begin(), v.end()) #define Lower_bound(v, y) \ distance(v.begin(), lower_bound(v.begin(), v.end(), y)) #define Upper_bound(v, y) \ distance(v.begin(), upper_bound(v.begin(), v.end(), y)) #define pb push_back using ll = long long; using ull = unsigned long long; const ll mod = 1000000007; using P = pair<ll, ll>; using T = tuple<ll, ll, ll>; using vll = vector<ll>; using vP = vector<P>; using vT = vector<T>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vvP = vector<vector<P>>; using dqll = deque<ll>; ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0}; ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0}; template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } /* Macros reg. ends here */ const ll INF = 1000000000000000000ll; ll solve(ll X,ll n,ll m,vector<ll> u,vector<ll> v,vector<ll> s) { // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); vvP to(n); ll sol = -INF; rep(i, m) { to[u[i]].emplace_back(v[i], s[i]); to[v[i]].emplace_back(u[i], s[i]); } vll as(n, 0), bs(n, 0); // ax + b queue<ll> q; q.push(0); as[0] = 1, bs[0] = 0; while (!q.empty()) { ll u = q.front(); q.pop(); ll a = as[u], b = bs[u]; for (auto [v, s] : to[u]) { ll c = -a, d = s - b; if (as[v] != 0) { ll cc = as[v], dd = bs[v]; if (cc == c) { if (dd == d) continue; else { return 0; } } else { bool cond = ((d - dd) % 2 == 0) && (((d - dd) / (cc - c)) >= 1); if (cond) { ll csol = (d - dd) / (cc - c); if(sol >= 1 && csol != sol) { return 0; } if(sol == -INF) sol = csol; } else { return 0; } } } else { as[v] = c; bs[v] = d; q.push(v); } } } ll l = 1, r = X; rep(i, n){ ll a = as[i], b = bs[i]; if(a == 1){ chmax(l, 1 - b); chmin(r, X - b); } else { assert(a == -1); chmin(r, b - 1); chmax(l, b - X); } } ll ans = max(0LL, r - l + 1); if(sol >= 1) chmin(ans, 1LL); return ans; } class UnionFind{ public: vector<ll> par; vector<ll> siz; UnionFind(ll sz_):par(sz_),siz(sz_,1ll){ for(int i=0;i<sz_;i++) par[i]=i; } void init(ll sz_){ par.resize(sz_); siz.assign(sz_,1ll); for(int i=0;i<sz_;i++) par[i]=i; } ll root(ll x){ while(par[x]!=x){ x=par[x]=par[par[x]]; } return x; } bool merge(ll x,ll y){ x=root(x); y=root(y); if(x==y) return false; if(siz[x]<siz[y]) swap(x,y); siz[x]+=siz[y]; par[y]=x; return true; } bool issame(ll x,ll y){ return root(x)==root(y); } ll size(ll x){ return siz[root(x)]; } }; int main(){ ll n,m,K; cin>>n>>m>>K; assert(m>=10000); vector<ll> a(m),b(m),c(m); UnionFind T(n); for(int i=0;i<m;i++){ cin>>a[i]>>b[i]>>c[i]; a[i]--; b[i]--; T.merge(a[i],b[i]); } vector<vector<ll>> p(n); for(int i=0;i<n;i++){ p[T.root(i)].push_back(i); } vector<vector<ll>> h(n); for(int i=0;i<m;i++){ h[T.root(a[i])].pb(i); } ll ans=1,ans2=1; for(int i=0;i<n;i++){ vector<ll> u,v,s; map<ll,ll> M; for(int j=0;j<p[i].size();j++){ M[p[i][j]]=j; } for(int j=0;j<h[i].size();j++){ u.pb(M[a[h[i][j]]]); v.pb(M[b[h[i][j]]]); s.pb(c[h[i][j]]); } if(p[i].size()==0) continue; ans*=solve(K,p[i].size(),h[i].size(),u,v,s); ans%=mod; ans2*=solve(K-1,p[i].size(),h[i].size(),u,v,s); ans2%=mod; // cout<<solve(K,p[i].size(),h[i].size(),u,v,s)<<" "<<solve(K-1,p[i].size(),h[i].size(),u,v,s)<<endl; } cout<<((ans-ans2)%mod+mod)%mod<<endl; }