結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 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 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 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 2 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 2 ms
5,376 KB
testcase_34 AC 1 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 97 ms
20,160 KB
testcase_41 AC 72 ms
15,908 KB
testcase_42 AC 47 ms
11,836 KB
testcase_43 AC 80 ms
17,188 KB
testcase_44 AC 100 ms
20,012 KB
testcase_45 AC 93 ms
17,860 KB
testcase_46 AC 65 ms
13,604 KB
testcase_47 AC 43 ms
9,912 KB
testcase_48 AC 68 ms
14,116 KB
testcase_49 AC 83 ms
16,332 KB
testcase_50 AC 72 ms
14,824 KB
testcase_51 AC 54 ms
12,588 KB
testcase_52 AC 74 ms
16,108 KB
testcase_53 AC 101 ms
20,048 KB
testcase_54 AC 55 ms
12,848 KB
testcase_55 AC 534 ms
46,468 KB
testcase_56 AC 415 ms
29,076 KB
testcase_57 AC 443 ms
33,588 KB
testcase_58 AC 475 ms
38,836 KB
testcase_59 AC 454 ms
33,936 KB
testcase_60 AC 364 ms
24,116 KB
testcase_61 AC 516 ms
44,928 KB
testcase_62 AC 555 ms
51,196 KB
testcase_63 AC 512 ms
46,764 KB
testcase_64 AC 346 ms
25,740 KB
testcase_65 AC 213 ms
40,844 KB
testcase_66 AC 296 ms
44,168 KB
testcase_67 AC 296 ms
45,688 KB
testcase_68 AC 610 ms
76,732 KB
testcase_69 AC 419 ms
57,508 KB
testcase_70 AC 591 ms
77,092 KB
testcase_71 AC 156 ms
31,852 KB
testcase_72 AC 351 ms
58,904 KB
testcase_73 AC 621 ms
70,544 KB
testcase_74 AC 587 ms
66,884 KB
testcase_75 AC 2 ms
5,376 KB
testcase_76 AC 3 ms
5,376 KB
testcase_77 AC 228 ms
45,268 KB
testcase_78 AC 318 ms
55,900 KB
testcase_79 AC 9 ms
5,504 KB
testcase_80 AC 12 ms
6,144 KB
testcase_81 AC 11 ms
5,380 KB
testcase_82 AC 26 ms
9,316 KB
testcase_83 AC 63 ms
14,940 KB
61_evil_bias_nocross_01.txt AC 99 ms
18,880 KB
61_evil_bias_nocross_02.txt AC 71 ms
15,008 KB
61_evil_bias_nocross_03.txt AC 46 ms
12,728 KB
61_evil_bias_nocross_04.txt AC 76 ms
18,596 KB
61_evil_bias_nocross_05.txt AC 95 ms
21,668 KB
61_evil_bias_nocross_06.txt AC 86 ms
19,948 KB
61_evil_bias_nocross_07.txt AC 54 ms
12,076 KB
61_evil_bias_nocross_08.txt AC 73 ms
15,168 KB
61_evil_bias_nocross_09.txt AC 95 ms
21,792 KB
61_evil_bias_nocross_10.txt AC 51 ms
13,992 KB
61_evil_bias_nocross_11.txt AC 63 ms
16,096 KB
61_evil_bias_nocross_12.txt AC 90 ms
20,920 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