結果

問題 No.2160 みたりのDominator
ユーザー hotman78hotman78
提出日時 2022-12-08 13:23:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 520 ms / 2,000 ms
コード長 2,645 bytes
コンパイル時間 2,975 ms
コンパイル使用メモリ 235,928 KB
実行使用メモリ 77,216 KB
最終ジャッジ日時 2024-04-22 12:08:29
合計ジャッジ時間 16,302 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 1 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 84 ms
20,160 KB
testcase_41 AC 64 ms
15,912 KB
testcase_42 AC 43 ms
11,832 KB
testcase_43 AC 68 ms
17,320 KB
testcase_44 AC 86 ms
20,020 KB
testcase_45 AC 81 ms
17,860 KB
testcase_46 AC 58 ms
13,604 KB
testcase_47 AC 38 ms
10,040 KB
testcase_48 AC 62 ms
14,116 KB
testcase_49 AC 74 ms
16,420 KB
testcase_50 AC 64 ms
14,952 KB
testcase_51 AC 47 ms
12,596 KB
testcase_52 AC 65 ms
15,936 KB
testcase_53 AC 83 ms
20,000 KB
testcase_54 AC 47 ms
13,100 KB
testcase_55 AC 452 ms
46,648 KB
testcase_56 AC 375 ms
28,948 KB
testcase_57 AC 403 ms
33,584 KB
testcase_58 AC 425 ms
39,092 KB
testcase_59 AC 392 ms
34,072 KB
testcase_60 AC 329 ms
23,988 KB
testcase_61 AC 443 ms
44,928 KB
testcase_62 AC 483 ms
51,312 KB
testcase_63 AC 450 ms
46,536 KB
testcase_64 AC 316 ms
25,612 KB
testcase_65 AC 195 ms
40,968 KB
testcase_66 AC 246 ms
44,160 KB
testcase_67 AC 255 ms
45,788 KB
testcase_68 AC 520 ms
76,732 KB
testcase_69 AC 359 ms
57,380 KB
testcase_70 AC 503 ms
77,216 KB
testcase_71 AC 127 ms
31,984 KB
testcase_72 AC 300 ms
58,828 KB
testcase_73 AC 520 ms
70,496 KB
testcase_74 AC 507 ms
66,884 KB
testcase_75 AC 3 ms
5,376 KB
testcase_76 AC 2 ms
5,376 KB
testcase_77 AC 194 ms
45,376 KB
testcase_78 AC 274 ms
55,836 KB
testcase_79 AC 9 ms
5,504 KB
testcase_80 AC 12 ms
6,144 KB
testcase_81 AC 10 ms
5,632 KB
testcase_82 AC 26 ms
9,196 KB
testcase_83 AC 58 ms
14,692 KB
61_evil_bias_nocross_01.txt AC 82 ms
19,004 KB
61_evil_bias_nocross_02.txt AC 62 ms
15,012 KB
61_evil_bias_nocross_03.txt AC 43 ms
12,732 KB
61_evil_bias_nocross_04.txt AC 64 ms
18,592 KB
61_evil_bias_nocross_05.txt AC 83 ms
21,800 KB
61_evil_bias_nocross_06.txt AC 73 ms
19,948 KB
61_evil_bias_nocross_07.txt AC 44 ms
12,072 KB
61_evil_bias_nocross_08.txt AC 63 ms
15,040 KB
61_evil_bias_nocross_09.txt AC 83 ms
21,668 KB
61_evil_bias_nocross_10.txt AC 47 ms
13,996 KB
61_evil_bias_nocross_11.txt AC 53 ms
16,224 KB
61_evil_bias_nocross_12.txt AC 74 ms
20,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/scc>
#include<atcoder/dsu>
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]){
                g[n2-2].emplace_back(n2-1,n[i]+1);
                pre+=n[i];
                continue;
            }
            g[n2-2].emplace_back(now,st[now]-pre+1);
            while(1){
                if(st[now+1]-pre>=n[i])break;
                g[now].emplace_back(now+1,(st[now+1]-pre+1)-(st[now]-pre+1));
                now++;
            }
            g[now].emplace_back(n2-1,(n[i]+1)-(st[now]-pre+1));
            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();
    vector<vector<pair<lint,lint>>>g2(sz);
    vector<int>id(n2);
    rep(i,sz){
        for(auto s:res[i]){
            id[s]=i;
        }
    }
    rep(j,sz){
        map<lint,lint>l;
        for(auto i:res[j]){
            for(auto [e,c]:g[i]){
                if(id[i]==id[e])continue;
                if(l[id[e]]==0)l[id[e]]=1;
                l[id[e]]*=c;
            }
        }
        for(auto [e,c]:l){
            g2[j].emplace_back(e,c);
        }
    }
    lint ans=0,tmp=1;
    vector<lint>div(sz,1),deg(sz);
    rep(i,sz){
        for(auto [e,c]:g2[i]){
            deg[e]++;
        }
    }
    rep(i,sz-1){
        if(deg[i]==1&&g2[i].size()==1)continue;
        tmp/=div[i];
        for(auto [e,c]:g2[i]){
            lint to=e;
            while(deg[to]==1&&g2[to].size()==1){
                c+=g2[to][0].second;
                to=g2[to][0].first;
            }
            tmp*=c;
            div[to]*=c;
        }
        //cerr<<tmp<<endl;
        ans+=tmp;
    }
    cout<<ans<<endl;
/**/}
0