結果
| 問題 |
No.1984 [Cherry 4th Tune *] Dilemma
|
| コンテスト | |
| ユーザー |
planes
|
| 提出日時 | 2022-06-28 16:27:14 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 2,694 bytes |
| コンパイル時間 | 2,339 ms |
| コンパイル使用メモリ | 189,004 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-08 14:07:52 |
| 合計ジャッジ時間 | 7,818 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 68 |
コンパイルメッセージ
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});
| ~~~~~~~~~~~~~~^~
ソースコード
#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;
}
}
planes