結果

問題 No.2160 みたりのDominator
ユーザー tko919tko919
提出日時 2022-12-23 12:13:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 7,030 bytes
コンパイル時間 2,528 ms
コンパイル使用メモリ 213,168 KB
実行使用メモリ 66,244 KB
最終ジャッジ日時 2023-08-11 11:49:32
合計ジャッジ時間 17,403 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 77 ms
50,752 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 89 ms
66,244 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 116 ms
44,944 KB
testcase_41 AC 105 ms
45,336 KB
testcase_42 AC 64 ms
27,776 KB
testcase_43 AC 89 ms
34,444 KB
testcase_44 AC 117 ms
43,476 KB
testcase_45 AC 112 ms
40,088 KB
testcase_46 AC 94 ms
37,372 KB
testcase_47 AC 53 ms
21,460 KB
testcase_48 AC 69 ms
24,696 KB
testcase_49 AC 83 ms
29,548 KB
testcase_50 AC 78 ms
29,696 KB
testcase_51 AC 72 ms
31,016 KB
testcase_52 AC 100 ms
41,352 KB
testcase_53 AC 114 ms
42,932 KB
testcase_54 AC 65 ms
26,280 KB
testcase_55 AC 183 ms
36,992 KB
testcase_56 AC 99 ms
31,468 KB
testcase_57 AC 130 ms
33,264 KB
testcase_58 AC 174 ms
48,128 KB
testcase_59 AC 144 ms
37,420 KB
testcase_60 AC 83 ms
48,296 KB
testcase_61 AC 164 ms
34,948 KB
testcase_62 AC 213 ms
50,284 KB
testcase_63 AC 181 ms
38,804 KB
testcase_64 AC 72 ms
37,176 KB
testcase_65 AC 108 ms
33,500 KB
testcase_66 AC 109 ms
27,940 KB
testcase_67 AC 115 ms
29,292 KB
testcase_68 AC 225 ms
45,000 KB
testcase_69 AC 149 ms
34,080 KB
testcase_70 AC 227 ms
46,120 KB
testcase_71 AC 94 ms
31,224 KB
testcase_72 AC 192 ms
46,720 KB
testcase_73 AC 202 ms
37,304 KB
testcase_74 AC 188 ms
34,780 KB
testcase_75 AC 40 ms
31,868 KB
testcase_76 AC 32 ms
25,736 KB
testcase_77 AC 149 ms
47,692 KB
testcase_78 AC 178 ms
47,892 KB
testcase_79 AC 24 ms
18,108 KB
testcase_80 AC 27 ms
20,000 KB
testcase_81 AC 51 ms
35,572 KB
testcase_82 AC 60 ms
38,320 KB
testcase_83 AC 68 ms
31,336 KB
61_evil_bias_nocross_01.txt AC 116 ms
44,936 KB
61_evil_bias_nocross_02.txt AC 106 ms
45,328 KB
61_evil_bias_nocross_03.txt AC 60 ms
27,712 KB
61_evil_bias_nocross_04.txt AC 82 ms
34,404 KB
61_evil_bias_nocross_05.txt AC 106 ms
43,252 KB
61_evil_bias_nocross_06.txt AC 112 ms
45,428 KB
61_evil_bias_nocross_07.txt AC 71 ms
30,896 KB
61_evil_bias_nocross_08.txt AC 101 ms
41,572 KB
61_evil_bias_nocross_09.txt AC 100 ms
42,812 KB
61_evil_bias_nocross_10.txt AC 59 ms
26,136 KB
61_evil_bias_nocross_11.txt AC 77 ms
33,980 KB
61_evil_bias_nocross_12.txt AC 102 ms
38,652 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