結果
| 問題 |
No.119 旅行のツアーの問題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-01-07 00:07:26 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 1,691 bytes |
| コンパイル時間 | 1,612 ms |
| コンパイル使用メモリ | 169,812 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-21 10:43:23 |
| 合計ジャッジ時間 | 2,488 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 |
コンパイルメッセージ
main.cpp: In instantiation of ‘void Dinic<V, INF, MAXV>::add_edge(int, int, V) [with V = int; V INF = 33554432; int MAXV = 200]’:
main.cpp:88:17: required from here
main.cpp:49:56: warning: narrowing conversion of ‘(&((Dinic<int, 33554432, 200>*)this)->Dinic<int, 33554432, 200>::G.std::array<std::vector<Dinic<int, 33554432, 200>::edge, std::allocator<Dinic<int, 33554432, 200>::edge> >, 200>::operator[](((std::array<std::vector<Dinic<int, 33554432, 200>::edge, std::allocator<Dinic<int, 33554432, 200>::edge> >, 200>::size_type)to)))->std::vector<Dinic<int, 33554432, 200>::edge, std::allocator<Dinic<int, 33554432, 200>::edge> >::size()’ from ‘std::vector<Dinic<int, 33554432, 200>::edge, std::allocator<Dinic<int, 33554432, 200>::edge> >::size_type’ {aka ‘long unsigned int’} to ‘int’ [-Wnarrowing]
49 | G[from].push_back((edge){to, G[to].size(), cap});
| ~~~~~~~~~~^~
main.cpp:50:61: warning: narrowing conversion of ‘((&((Dinic<int, 33554432, 200>*)this)->Dinic<int, 33554432, 200>::G.std::array<std::vector<Dinic<int, 33554432, 200>::edge, std::allocator<Dinic<int, 33554432, 200>::edge> >, 200>::operator[](((std::array<std::vector<Dinic<int, 33554432, 200>::edge, std::allocator<Dinic<int, 33554432, 200>::edge> >, 200>::size_type)from)))->std::vector<Dinic<int, 33554432, 200>::edge, std::allocator<Dinic<int, 33554432, 200>::edge> >::size() - 1)’ from ‘std::vector<Dinic<int, 33554432, 200>::edge, std::allocator<Dinic<int, 33554432, 200>::edge> >::size_type’ {aka ‘long unsigned int’} to ‘int’ [-Wnarrowing]
50 | G[to].push_back((edge){from, G[from].size() - 1, 0});
| ~~~~~~~~~~~~~~~^~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
template<class V, V INF, int MAXV>
class Dinic {
private:
struct edge { int to, rev; V cap; };
array<vector<edge>, MAXV> G;
array<int, MAXV> level, iter;
void bfs(int s){
level.fill(-1);
queue<int> Q;
level[s] = 0;
Q.push(s);
while(!Q.empty()){
int v = Q.front(); Q.pop();
for(const auto &e : G[v]){
if(e.cap > 0 && level[e.to] < 0){
level[e.to] = level[v] + 1;
Q.push(e.to);
}
}
}
}
V dfs(int v, int t, V f){
if(v == t)return f;
for(int &i=iter[v];i<G[v].size();i++){
auto &e = G[v][i];
if(e.cap > 0 && level[v] < level[e.to]){
V 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;
}
public:
Dinic(){}
void add_edge(int from, int to, V cap){
G[from].push_back((edge){to, G[to].size(), cap});
G[to].push_back((edge){from, G[from].size() - 1, 0});
}
V max_flow(int s, int t){
V flow = 0;
for(;;){
bfs(s);
if(level[t] < 0)return flow;
iter.fill(0);
V f;
while((f = dfs(s, t, INF)) > 0){
flow += f;
}
}
}
};
int N, B[100], C[100];
int M, D[1000], E[1000];
int main(){
const int INF = 1 << 25;
cin >> N;
for(int i=0;i<N;i++)
cin >> B[i] >> C[i];
cin >> M;
for(int i=0;i<M;i++)
cin >> D[i] >> E[i];
Dinic<int, INF, 200> dinic;
int s = 2 * N, t = s + 1;
int res = 0;
for(int i=0;i<N;i++){
dinic.add_edge(s, i, B[i]);
dinic.add_edge(i, N+i, INF);
dinic.add_edge(N+i, t, C[i]);
res += B[i] + C[i];
}
for(int i=0;i<M;i++){
dinic.add_edge(D[i], N+E[i], INF);
}
res -= dinic.max_flow(s, t);
cout << res << endl;
return 0;
}