結果

問題 No.1984 [Cherry 4th Tune *] Dilemma
ユーザー planesplanes
提出日時 2022-06-28 16:27:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 2,694 bytes
コンパイル時間 2,428 ms
コンパイル使用メモリ 184,324 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-26 01:50:43
合計ジャッジ時間 6,833 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 3 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 3 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 3 ms
6,944 KB
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 3 ms
6,944 KB
testcase_26 AC 3 ms
6,944 KB
testcase_27 AC 3 ms
6,940 KB
testcase_28 AC 3 ms
6,944 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 4 ms
6,940 KB
testcase_31 AC 3 ms
6,940 KB
testcase_32 AC 3 ms
6,940 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,944 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 2 ms
6,944 KB
testcase_41 AC 2 ms
6,944 KB
testcase_42 AC 2 ms
6,940 KB
testcase_43 AC 2 ms
6,944 KB
testcase_44 AC 3 ms
6,940 KB
testcase_45 AC 3 ms
6,940 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 2 ms
6,944 KB
testcase_48 AC 3 ms
6,944 KB
testcase_49 AC 2 ms
6,940 KB
testcase_50 AC 3 ms
6,940 KB
testcase_51 AC 2 ms
6,940 KB
testcase_52 AC 2 ms
6,944 KB
testcase_53 AC 3 ms
6,940 KB
testcase_54 AC 2 ms
6,940 KB
testcase_55 AC 2 ms
6,940 KB
testcase_56 AC 2 ms
6,944 KB
testcase_57 AC 2 ms
6,940 KB
testcase_58 AC 2 ms
6,940 KB
testcase_59 AC 3 ms
6,940 KB
testcase_60 AC 2 ms
6,944 KB
testcase_61 AC 3 ms
6,940 KB
testcase_62 AC 2 ms
6,940 KB
testcase_63 AC 3 ms
6,940 KB
testcase_64 AC 2 ms
6,940 KB
testcase_65 AC 3 ms
6,940 KB
testcase_66 AC 2 ms
6,944 KB
testcase_67 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'void add_edge(ll, ll, ll)':
main.cpp:16:41: warning: narrowing conversion of '(& G.std::vector<std::vector<edge> >::operator[](((std::vector<std::vector<edge> >::size_type)to)))->std::vector<edge>::size()' from 'std::vector<edge>::size_type' {aka 'long unsigned int'} to 'll' {aka 'long long int'} [-Wnarrowing]
   16 |     G[from].push_back({to,cap,G[to].size()});
      |                               ~~~~~~~~~~^~
main.cpp:17:43: warning: narrowing conversion of '((& G.std::vector<std::vector<edge> >::operator[](((std::vector<std::vector<edge> >::size_type)from)))->std::vector<edge>::size() - 1)' from 'std::vector<edge>::size_type' {aka 'long unsigned int'} to 'll' {aka 'long long int'} [-Wnarrowing]
   17 |     G[to].push_back({from,0,G[from].size()-1});
      |                             ~~~~~~~~~~~~~~^~

ソースコード

diff #

#include <bits/stdc++.h> 
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 #define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
ll INF=2e15;

struct edge {ll to,cap,rev;};
ll V;
vector<vector<edge>> G;
vector<ll> level;
vector<ll> iter;

void add_edge( ll from,ll to,ll cap){
    G[from].push_back({to,cap,G[to].size()});
    G[to].push_back({from,0,G[from].size()-1});
}

void bfs(ll s) {
    level=vector<ll> (V,-1);

    queue<ll> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()) {
        ll v=que.front();
        que.pop();
        for(ll i=0;i<G[v].size();i++) {
            edge &e=G[v][i];
            if(e.cap>0&&level[e.to]<0) {
                level[e.to]=level[v]+1;
                que.push(e.to);
            }
        }
    }
}


ll dfs(ll v,ll t,ll f) {
    if(v==t) return f;
    for(ll &i=iter[v];i<G[v].size();i++) {
        edge &e=G[v][i];
        if(e.cap>0&&level[v]<level[e.to]) {
            ll d=dfs(e.to,t,min(f,e.cap));
            if(d>0) {
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}

ll max_flow(ll s,ll t) {
    ll flow=0;
    for(;;) {
        bfs(s);
        if(level[t]<0) return flow;
       iter=vector<ll> (V,0);
        ll f;
        while((f=dfs(s,t,INF))>0) {
            flow+=f;
        }
    }
}



vector<bool> note;

void solve(ll i) {
  if(note[i]) return ;
  note[i]=true;

  for(auto x:G[i]) {
    if(x.cap>0) solve(x.to);
  }
}



int main() {
  ll N,M,K,P;
  cin>>N>>M>>K>>P;
vector<ll> E(N);
ll ans=0;
for(ll i=0;i<N;i++){
   cin>>E[i];
   ans+=E[i];
}

vector<ll> F(M);
for(ll i=0;i<M;i++) {
  cin>>F[i];
  ans+=F[i];
}

vector<ll> v(K);
for(ll i=0;i<K;i++) cin>>v[i];


V=N+M+K+2;
G=vector<vector<edge>> (V,vector<edge>(0));

for(ll i=0;i<N;i++) {
  add_edge(0,i+1,E[i]);
}

for(ll i=0;i<M;i++) {
  add_edge(N+1+i,N+M+K+1,F[i]);
}

for(ll i=0;i<K;i++) {
  add_edge(N+M+1+i,N+M+K+1,v[i]);
}

for(ll i=0;i<N;i++) {
  ll L;cin>>L;
  for(ll j=0;j<L;j++) {
    ll A;cin>>A;
    add_edge(i+1,N+M+A,INF);
  }
}

for(ll i=0;i<P;i++) {
  ll I,J;cin>>I>>J;
add_edge(I,N+J,INF);
}


ll t=max_flow(0,N+M+K+1);
cout<<ans-t<<endl;

note=vector<bool> (N+M+K+2,false);

solve(0);

vector<pair<string,ll>> memo(0);
for(ll i=N+M+1;i<=N+M+K;i++) {
  if(note[i]) {
    memo.push_back(make_pair("Preparation",i-N-M));
  }
}

for(ll i=N+1;i<=N+M;i++) {
  if(!note[i]) {
    memo.push_back(make_pair("Action",i-N));
  }
}

for(ll i=1;i<=N;i++) {
  if(note[i]) {
    memo.push_back(make_pair("Goal",i));
  }
}

cout<<memo.size()<<endl;
for(auto x:memo) {
  cout<<x.first<<" "<<x.second<<endl;
}


}


0