結果
問題 |
No.2160 みたりのDominator
|
ユーザー |
![]() |
提出日時 | 2022-12-04 20:01:01 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,805 bytes |
コンパイル時間 | 2,769 ms |
コンパイル使用メモリ | 220,820 KB |
最終ジャッジ日時 | 2025-02-09 05:06:30 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 81 WA * 12 |
ソースコード
#include<bits/stdc++.h> #include<atcoder/scc> using namespace std; using namespace atcoder; #define rep(i,n) for(int i=0;i<int(n);++i) using lint=long long; int main(){ array<int,3>n; int m,ns=0; rep(i,3)cin>>n[i]; rep(i,3)ns+=n[i]; cin>>m; vector<int>u(m),v(m),st; rep(i,m){ cin>>u[i]>>v[i]; u[i]--;v[i]--; st.emplace_back(u[i]); st.emplace_back(v[i]); } st.emplace_back(ns); st.emplace_back(ns+1); sort(st.begin(),st.end()); st.erase(unique(st.begin(),st.end()),st.end()); int n2=st.size(); vector<vector<pair<int,int>>> g(n2); scc_graph scc(n2); auto get=[&](int i){ return lower_bound(st.begin(),st.end(),i)-st.begin(); }; //cerr<<n2<<endl; { int now=0,pre=0; rep(i,3){ //cerr<<st[now]<<endl; if(st[now]>=pre+n[i]){ //cerr<<"a"<<n[i]<<endl; g[n2-2].emplace_back(n2-1,n[i]+1); pre+=n[i]; continue; } g[n2-2].emplace_back(now,st[now]+1-pre); while(1){ if(now+1>=n2-2||st[now+1]>=pre+n[i])break; //cerr<<"tmp"<<endl; g[now].emplace_back(now+1,st[now+1]-st[now]); now++; } //cerr<<"pre"<<pre<<" "<<pre+n[i]-st[now]<<endl; g[now].emplace_back(n2-1,pre+n[i]-st[now]); now++; pre+=n[i]; } } rep(i,m){ g[get(u[i])].emplace_back(get(v[i]),1); g[get(v[i])].emplace_back(get(u[i]),1); } rep(i,n2){ for(auto [e,c]:g[i]){ scc.add_edge(i,e); } } auto res=scc.scc(); int sz=res.size(); //cerr<<sz<<endl; vector<vector<int>>g2(sz); vector<int>id(n2+2); vector<lint>v1(sz),v2(sz),v3(sz,1),v4(sz),v5(sz); rep(i,sz){ for(auto s:res[i]){ //cerr<<i<<" "<<s<<endl; id[s]=i; } } rep(i,n2){ for(auto [e,c]:g[i]){ if(id[i]==id[e])continue; if(id[e]==id[i]+1){ //cerr<<"b"<<c<<endl; v3[id[i]]*=c; v4[id[i]]++; continue; } //cerr<<"c"<<c<<endl; v1[id[i]]+=c; v1[id[e]]-=c; v2[id[i]]+=c*c; v2[id[e]]-=c*c; v5[id[i]]++; v5[id[e]]--; } } lint ans=0,tmp=0,tmp2=0,tmp3=0; rep(i,sz-1){ tmp+=v1[i]; tmp2+=v2[i]; tmp3+=v5[i]; if(v4[i]+tmp3!=3)continue; //cerr<<tmp<<" "<<tmp2<<" "<<v3[i]<<" "<<v4[i]<<endl; if(v4[i]==1)ans+=(tmp*tmp-tmp2)/2*v3[i]; else if(v4[i]==2)ans+=tmp*v3[i]; else ans+=v3[i]; } cout<<ans<<endl; /**/}