結果
問題 | No.2295 Union Path Query (Medium) |
ユーザー | Ecrade_ |
提出日時 | 2023-05-05 23:13:14 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,982 bytes |
コンパイル時間 | 1,756 ms |
コンパイル使用メモリ | 170,316 KB |
実行使用メモリ | 22,528 KB |
最終ジャッジ日時 | 2024-11-23 11:43:24 |
合計ジャッジ時間 | 11,698 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 82 ms
20,864 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | AC | 97 ms
20,736 KB |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | WA | - |
testcase_55 | WA | - |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 998244353; ll t = 1,n,m,k,q,l,r,a,b,c,u,v,x,y,z,o,X,hd[200009],tot,dep[200009],rt[200009],id[200009],sz[200009],dis[200009],ans[200009]; string s; struct st{ll x,y,z; /*bool operator < (const st &a) const{return x < a.x;};*/}eg[400009]; void addedge(ll u,ll v,ll w){eg[++ tot] = (st){v,hd[u],w},hd[u] = tot;} bool cmp(const st &a,const st &b){return a.x < b.x;} inline ll read(){ ll s = 0,w = 1; char ch = getchar(); while (ch > '9' || ch < '0'){ if (ch == '-') w = -1; ch = getchar();} while (ch <= '9' && ch >= '0') s = (s << 1) + (s << 3) + (ch ^ 48),ch = getchar(); return s * w; } ll qp(ll x,ll y){ ll a = 1,b = x; while (y){ if (y & 1) a = a * b % mod; b = b * b % mod,y >>= 1; } return a; } inline void add(ll &x,ll y){x += y; if (x >= mod) x -= mod;} ll find(ll x){return x == id[x] ? x : id[x] = find(id[x]);} void dfs(ll u,ll fa,ll rt){ for (ll i = hd[u];i;i = eg[i].y){ ll v = eg[i].x; if (v == fa) continue; dis[v] = dis[u] ^ eg[i].z,dfs(v,u,rt); } } void merge(ll x,ll y,ll z){ ll qwq = find(x),awa = find(y); if (qwq == awa) return; if (sz[qwq] > sz[awa]) swap(x,y),swap(qwq,awa); id[qwq] = awa,ans[awa] += z * sz[qwq] % mod * sz[awa] % mod,sz[awa] += sz[qwq],ans[awa] %= mod; dis[x] = z,addedge(x,y,z),addedge(y,x,z),dfs(x,y,awa); } ll query(ll x,ll y){ if (x == y) return 0; return max(dis[x],dis[y]); } int main(){//t = read(); while (t --){ n = read(),X = read() + 1,q = read(); for (ll i = 1;i <= n;i += 1){ rt[i] = id[i] = i,sz[i] = 1; } while (q --){ o = read(); if (o == 1){ x = read() + 1,y = read(); merge(x,X,y); } if (o == 2){ x = read() + 1,y = read() + 1; if (find(x) != find(y)) puts("-1"); else{ ll qwq = query(x,y); X += qwq; printf("%lld\n",qwq); } } if (o == 3){ x = read() + 1; printf("%lld\n",ans[find(x)]); } if (o == 4) X += read(); X = (X + n - 1) % n + 1; } } return 0; }