fork download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <cstdlib>
  7. #include <vector>
  8. #include <set>
  9. #include <map>
  10. #include <queue>
  11. #include <stack>
  12. #include <list>
  13. #include <cmath>
  14. #include <iomanip>
  15. #define dibs reserve
  16. #define OVER9000 1234567890123456789LL
  17. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  18. #define tisic 47
  19. #define soclose 1e-8
  20. #define chocolate win
  21. // so much chocolate
  22. #define patkan 9
  23. #define ff first
  24. #define ss second
  25. #define abs(x) ((x < 0)?-(x):x)
  26. #define uint unsigned int
  27. #define dbl long double
  28. using namespace std;
  29. // mylittledoge
  30.  
  31. int main() {
  32. cin.sync_with_stdio(0);
  33. cin.tie(0);
  34. int N,M,K;
  35. cin >> N >> M >> K;
  36. vector< vector<bool> > G(N,vector<bool>(M,true));
  37. for(int i =0; i < K; i++) {
  38. int a,b;
  39. cin >> a >> b;
  40. G[--a][--b] =false;}
  41.  
  42. // max. indep. set v grafe G
  43. vector< vector<long long> > F(N+M+2,vector<long long>(N+M+2,0));
  44. for(int i =0; i < N; i++) cin >> F[0][i+1];
  45. for(int i =0; i < M; i++) cin >> F[N+1+i][N+1+M];
  46.  
  47. for(int i =1; i <= N; i++) for(int j =N+1; j <= N+M; j++)
  48. if(G[i-1][j-N-1]) F[i][j] =OVER9000;
  49.  
  50. queue<int> q;
  51. vector<long long> Fv(N+M+2,OVER9000);
  52. vector<int> ako(N+M+2,-1);
  53. while(true) {
  54. Fv.clear(); ako.clear();
  55. Fv.resize(N+M+2,OVER9000);
  56. ako.resize(N+M+2,-1);
  57. q.push(0);
  58. while(!q.empty()) {
  59. for(int i =0; i < N+M+2; i++) if(F[q.front()][i] > 0 && ako[i] == -1) {
  60. Fv[i] =min(Fv[q.front()],F[q.front()][i]);
  61. ako[i] =q.front();
  62. q.push(i);}
  63. q.pop();}
  64. if(ako[N+M+1] == -1) break;
  65.  
  66. int akt =N+M+1;
  67. long long f =Fv[N+M+1];
  68. while(akt > 0) {
  69. F[ako[akt]][akt] -=f;
  70. F[akt][ako[akt]] +=f;
  71. akt =ako[akt];}
  72. }
  73.  
  74. vector<bool> vis(N+M+2,false);
  75. q.push(0);
  76. vis[0] =true;
  77. while(!q.empty()) {
  78. for(int j =0; j < N+M+2; j++) if(!vis[j] && F[q.front()][j] > 0) {
  79. vis[j] =true;
  80. q.push(j);}
  81. q.pop();}
  82.  
  83. long long ans =0;
  84. vector<int> V1,V2;
  85. for(int i =1; i <= N; i++)
  86. // je v ind. sete?
  87. if(vis[i]) {
  88. V1.push_back(i);
  89. ans +=F[0][i]+F[i][0];}
  90. for(int i =N+1; i <= N+M; i++)
  91. if(!vis[i]) {
  92. V2.push_back(i-N);
  93. ans +=F[N+M+1][i]+F[i][N+M+1];}
  94.  
  95. cout << ans << "\n";
  96. cout << V1.size() << "\n";
  97. for(int i =0; i < V1.size(); i++) {
  98. if(i > 0) cout << " ";
  99. cout << V1[i];}
  100. cout << "\n";
  101. cout << V2.size() << "\n";
  102. for(int i =0; i < V2.size(); i++) {
  103. if(i > 0) cout << " ";
  104. cout << V2[i];}
  105. cout << "\n";
  106. return 0;}
  107.  
  108. // look at my code
  109. // my code is amazing
Runtime error #stdin #stdout #stderr 0.37s 3444KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc