結果

問題 No.2160 みたりのDominator
ユーザー tko919tko919
提出日時 2022-12-23 12:13:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 7,030 bytes
コンパイル時間 2,542 ms
コンパイル使用メモリ 215,908 KB
実行使用メモリ 66,480 KB
最終ジャッジ日時 2024-04-29 04:14:21
合計ジャッジ時間 13,552 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 80 ms
50,780 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 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 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 88 ms
66,480 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 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 126 ms
45,048 KB
testcase_41 AC 114 ms
45,404 KB
testcase_42 AC 67 ms
28,100 KB
testcase_43 AC 91 ms
34,424 KB
testcase_44 AC 120 ms
43,652 KB
testcase_45 AC 117 ms
40,180 KB
testcase_46 AC 98 ms
37,392 KB
testcase_47 AC 53 ms
21,796 KB
testcase_48 AC 73 ms
24,948 KB
testcase_49 AC 91 ms
29,576 KB
testcase_50 AC 82 ms
29,812 KB
testcase_51 AC 75 ms
31,176 KB
testcase_52 AC 105 ms
41,604 KB
testcase_53 AC 122 ms
43,148 KB
testcase_54 AC 66 ms
26,440 KB
testcase_55 AC 192 ms
37,072 KB
testcase_56 AC 109 ms
31,780 KB
testcase_57 AC 137 ms
33,460 KB
testcase_58 AC 176 ms
48,408 KB
testcase_59 AC 140 ms
37,488 KB
testcase_60 AC 84 ms
48,508 KB
testcase_61 AC 175 ms
35,320 KB
testcase_62 AC 239 ms
50,204 KB
testcase_63 AC 197 ms
38,848 KB
testcase_64 AC 64 ms
37,236 KB
testcase_65 AC 117 ms
33,620 KB
testcase_66 AC 113 ms
27,988 KB
testcase_67 AC 123 ms
29,672 KB
testcase_68 AC 246 ms
45,396 KB
testcase_69 AC 165 ms
34,148 KB
testcase_70 AC 241 ms
46,244 KB
testcase_71 AC 93 ms
31,460 KB
testcase_72 AC 200 ms
46,956 KB
testcase_73 AC 216 ms
37,540 KB
testcase_74 AC 199 ms
34,960 KB
testcase_75 AC 40 ms
32,096 KB
testcase_76 AC 32 ms
25,968 KB
testcase_77 AC 158 ms
47,900 KB
testcase_78 AC 180 ms
48,044 KB
testcase_79 AC 23 ms
18,512 KB
testcase_80 AC 30 ms
20,392 KB
testcase_81 AC 51 ms
35,748 KB
testcase_82 AC 61 ms
38,336 KB
testcase_83 AC 70 ms
31,644 KB
61_evil_bias_nocross_01.txt AC 116 ms
45,048 KB
61_evil_bias_nocross_02.txt AC 110 ms
45,396 KB
61_evil_bias_nocross_03.txt AC 60 ms
27,944 KB
61_evil_bias_nocross_04.txt AC 84 ms
34,560 KB
61_evil_bias_nocross_05.txt AC 108 ms
43,572 KB
61_evil_bias_nocross_06.txt AC 116 ms
45,440 KB
61_evil_bias_nocross_07.txt AC 73 ms
31,260 KB
61_evil_bias_nocross_08.txt AC 105 ms
41,612 KB
61_evil_bias_nocross_09.txt AC 102 ms
43,116 KB
61_evil_bias_nocross_10.txt AC 59 ms
26,456 KB
61_evil_bias_nocross_11.txt AC 78 ms
34,048 KB
61_evil_bias_nocross_12.txt AC 105 ms
38,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "library/Template/template.hpp"
#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
#line 2 "library/Utility/fastio.hpp"
#include <unistd.h>

class FastIO{
    static constexpr int L=1<<16;
    char rdbuf[L];
    int rdLeft=0,rdRight=0;
    inline void reload(){
        int len=rdRight-rdLeft;
        memmove(rdbuf,rdbuf+rdLeft,len);
        rdLeft=0,rdRight=len;
        rdRight+=fread(rdbuf+len,1,L-len,stdin);
    }
    inline bool skip(){
        for(;;){
            while(rdLeft!=rdRight and rdbuf[rdLeft]<=' ')rdLeft++;
            if(rdLeft==rdRight){
                reload();
                if(rdLeft==rdRight)return false;
            }
            else break;
        }
        return true;
    }
    template<typename T,enable_if_t<is_integral<T>::value,int> =0>inline bool _read(T& x){
        if(!skip())return false;
        if(rdLeft+20>=rdRight)reload();
        bool neg=false;
        if(rdbuf[rdLeft]=='-'){
            neg=true;
            rdLeft++;
        }
        x=0;
        while(rdbuf[rdLeft]>='0' and rdLeft<rdRight){
            x=x*10+(neg?-(rdbuf[rdLeft++]^48):(rdbuf[rdLeft++]^48));
        }
        return true;
    }
    template<typename T,enable_if_t<is_floating_point<T>::value,int> =0>inline bool _read(T& x){
        if(!skip())return false;
        if(rdLeft+20>=rdRight)reload();
        bool neg=false;
        if(rdbuf[rdLeft]=='-'){
            neg=true;
            rdLeft++;
        }
        x=0;
        while(rdbuf[rdLeft]>='0' and rdbuf[rdLeft]<='9' and rdLeft<rdRight){
            x=x*10+(rdbuf[rdLeft++]^48);
        }
        if(rdbuf[rdLeft]!='.')return true;
        rdLeft++;
        T base=.1;
        while(rdbuf[rdLeft]>='0' and rdbuf[rdLeft]<='9' and rdLeft<rdRight){
            x+=base*(rdbuf[rdLeft++]^48);
            base*=.1;
        }
        if(neg)x=-x;
        return true;
    }
    inline bool _read(char& x){
        if(!skip())return false;
        if(rdLeft+1>=rdRight)reload();
        x=rdbuf[rdLeft++];
        return true;
    }
    inline bool _read(string& x){
        if(!skip())return false;
        for(;;){
            int pos=rdLeft;
            while(pos<rdRight and rdbuf[pos]>' ')pos++;
            x.append(rdbuf+rdLeft,pos-rdLeft);
            if(rdLeft==pos)break;
            rdLeft=pos;
            if(rdLeft==rdRight)reload();
            else break;
        }
        return true;
    }
    template<typename T>inline bool _read(vector<T>& v){
        for(auto& x:v){
            if(!_read(x))return false;
        }
        return true;
    }

    char wtbuf[L],tmp[50];
    int wtRight=0;
    inline void flush(){
        fwrite(wtbuf,1,wtRight,stdout);
        wtRight=0;
    }
    inline void _write(const char& x){
        if(wtRight>L-32)flush();
        wtbuf[wtRight++]=x;
    }
    inline void _write(const string& x){
        for(auto& c:x)_write(c);
    }
    template<typename T,enable_if_t<is_integral<T>::value,int> =0>inline void _write(T x){
        if(wtRight>L-32)flush();
        if(x==0){
            _write('0');
            return;
        }
        else if(x<0){
            _write('-');
            if (__builtin_expect(x == std::numeric_limits<T>::min(), 0)) {
                switch (sizeof(x)) {
                case 2: _write("32768"); return;
                case 4: _write("2147483648"); return;
                case 8: _write("9223372036854775808"); return;
                }
            }
            x=-x;
        }
        int pos=0;
        while(x!=0){
            tmp[pos++]=char((x%10)|48);
            x/=10;
        }
        rep(i,0,pos)wtbuf[wtRight+i]=tmp[pos-1-i];
        wtRight+=pos;
    }
    template<typename T>inline void _write(const vector<T>& v){
        rep(i,0,v.size()){
            if(i)_write(' ');
            _write(v[i]);
        }
    }
public:
    FastIO(){}
    ~FastIO(){flush();}
    inline void read(){}
    template <typename Head, typename... Tail>inline void read(Head& head,Tail&... tail){
        assert(_read(head));
        read(tail...); 
    }
    template<bool ln=true,bool space=false>inline void write(){if(ln)_write('\n');}
    template <bool ln=true,bool space=false,typename Head, typename... Tail>inline void write(const Head& head,const Tail&... tail){
        if(space)_write(' ');
        _write(head);
        write<ln,true>(tail...); 
    }
};

/**
 * @brief Fast IO
 */
#line 3 "sol.cpp"

#line 2 "library/Graph/scc.hpp"

struct SCC{
    int n,m,cur;
    vector<vector<int>> g;
    vector<int> low,ord,id;
    SCC(int _n=0):n(_n),m(0),cur(0),g(_n),low(_n),ord(_n,-1),id(_n){}
    void resize(int _n){
        n=_n;
        g.resize(n);
        low.resize(n);
        ord.resize(n,-1);
        id.resize(n);
    }
    void add_edge(int u,int v){g[u].emplace_back(v);}
    void dfs(int v,vector<int>& used){
        ord[v]=low[v]=cur++;
        used.emplace_back(v);
        for(auto& nxt:g[v]){
            if(ord[nxt]==-1){
                dfs(nxt,used); chmin(low[v],low[nxt]);
            }
            else{
                chmin(low[v],ord[nxt]);
            }
        }
        if(ord[v]==low[v]){
            while(1){
                int add=used.back(); used.pop_back();
                ord[add]=n; id[add]=m;
                if(v==add)break;
            }
            m++;
        }
    }
    void run(){
        vector<int> used;
        rep(v,0,n)if(ord[v]==-1)dfs(v,used);
        for(auto& x:id)x=m-1-x;
    }
};

/**
 * @brief Strongly Connected Components
 */
#line 5 "sol.cpp"

FastIO io;
int main(){
    int n[3],m;
    rep(i,0,3)io.read(n[i]);
    io.read(m);

    int N=n[0]+n[1]+n[2]+2;
    int s=N-2,t=N-1;

    SCC scc(N);
    int offset=0;
    rep(i,0,3){
        if(n[i]){
            scc.add_edge(s,offset);
            scc.add_edge(offset+n[i]-1,t);
            rep(j,0,n[i]-1)scc.add_edge(offset+j,offset+j+1);
        }
        else scc.add_edge(s,t);
        offset+=n[i];
    }
    rep(_,0,m){
        int u,v;
        io.read(u,v);
        u--; v--;
        scc.add_edge(u,v);
        scc.add_edge(v,u);
    }
    scc.run();

    int N2=scc.m;
    s=scc.id[s],t=scc.id[t];
    if(s==t){
        io.write(0);
        return 0;
    }
    vector g2(N2,vector<int>());
    vector<int> cnt(N2);
    rep(u,0,N)for(auto& v:scc.g[u])if(scc.id[u]!=scc.id[v]){
        g2[scc.id[u]].push_back(scc.id[v]);
        cnt[scc.id[u]]++;
        cnt[scc.id[v]]++;
    }

    vector<ll> add(N2,1);
    rep(v,0,N2)if(cnt[v]!=2){
        for(auto& to:g2[v]){
            int nxt=to,w=1;
            while(cnt[nxt]==2)nxt=g2[nxt][0],w++;
            rep(x,v,nxt)add[x]*=w;
        }
    }

    ll ret=0;
    rep(x,0,N2-1)if(cnt[x]!=2)ret+=add[x];
    io.write(ret);
    return 0;
}
0