結果

問題 No.2713 Just Solitaire
ユーザー nonon
提出日時 2024-03-31 14:54:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 937 bytes
コンパイル時間 6,583 ms
コンパイル使用メモリ 204,456 KB
最終ジャッジ日時 2025-02-20 17:30:21
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/maxflow>
using namespace std;
int N,M,A[100],B[100],K[100];
bool bad[100][100];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>N>>M;
    for(int i=0;i<N;i++)cin>>A[i];
    for(int j=0;j<M;j++)cin>>B[j];
    for(int i=0;i<M;i++)
    {
        cin>>K[i];
        for(int j=0;j<K[i];j++)
        {
            int c;
            cin>>c;
            bad[i][c-1]=1;
        }
    }
    atcoder::mf_graph<long>G(N+M+2);
    for(int i=0;i<N;i++)
    {
        G.add_edge(N+M+1,M+i,A[i]);
    }
    long sum=0;
    for(int i=0;i<M;i++)
    {
        G.add_edge(i,M+N,B[i]);
        sum+=B[i];
    }
    for(int i=0;i<M;i++)
    {
        for(int j=0;j<N;j++)
        {
            if(bad[i][j])G.add_edge(j+M,i,1L<<50);
            else G.add_edge(i,j+M,0);
        }
    }
    cout<<sum-G.flow(N+M+1,N+M)<<endl;
    // for(auto e:G.edges())cout<<e.cap<<' '<<e.flow<<endl;
}
0