結果
問題 | No.119 旅行のツアーの問題 |
ユーザー |
![]() |
提出日時 | 2015-03-05 11:40:22 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 1,093 bytes |
コンパイル時間 | 564 ms |
コンパイル使用メモリ | 39,296 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-21 10:47:28 |
合計ジャッジ時間 | 1,210 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘void add_edge(int, int, int)’: main.cpp:15:44: warning: narrowing conversion of ‘e[v].std::vector<edge>::size()’ from ‘std::vector<edge>::size_type’ {aka ‘long unsigned int’} to ‘int’ [-Wnarrowing] 15 | e[u].push_back((edge){v,c,e[v].size()}); | ~~~~~~~~~^~ main.cpp:16:46: warning: narrowing conversion of ‘(e[u].std::vector<edge>::size() - 1)’ from ‘std::vector<edge>::size_type’ {aka ‘long unsigned int’} to ‘int’ [-Wnarrowing] 16 | e[v].push_back((edge){u,0,e[u].size()-1}); | ~~~~~~~~~~~^~ main.cpp: In function ‘int main()’: main.cpp:48:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 48 | scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:56:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 56 | scanf("%d %d",&a,&b); | ~~~~~^~~~~~~~~~~~~~~ main.cpp:63:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 63 | scanf("%d",&m); | ~~~~~^~~~~~~~~ main.cpp:66:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 66 | scanf("%d %d",&a,&b); | ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include<stdio.h> #include<string.h> #include<vector> #define V 82 #define INF 100000000 using namespace std; struct edge{ int to,cap,rev; }; vector<edge> e[V]; bool used[V]; void add_edge(int u,int v,int c){ e[u].push_back((edge){v,c,e[v].size()}); e[v].push_back((edge){u,0,e[u].size()-1}); } int dfs(int v,int t,int f){ if(v==t)return f; used[v]=true; for(int i=0;i<e[v].size();i++){ edge &g=e[v][i]; if(!used[g.to]&&g.cap>0){ int d=dfs(g.to,t,min(f,g.cap)); if(d>0){ g.cap-=d; e[g.to][g.rev].cap+=d; return d; } } } return 0; } int max_flow(int s,int t){ int ans=0; while(1){ memset(used,0,sizeof(used)); int f=dfs(s,t,INF); if(f==0)return ans; ans+=f; } } int main(){ int n,i; scanf("%d",&n); //0 //1~n //n+1~n*2 //n*2+1 int s=0; for(i=0;i<n;i++){ int a,b; scanf("%d %d",&a,&b); s+=a+b; add_edge(0,i+1,a); add_edge(n+i+1,n*2+1,b); add_edge(i+1,n+i+1,INF); } int m; scanf("%d",&m); for(i=0;i<m;i++){ int a,b; scanf("%d %d",&a,&b); add_edge(a+1,n+b+1,INF); } printf("%d\n",s-max_flow(0,n*2+1)); return 0; }