#include using namespace std; template class Dinic { private: struct edge { int to, rev; V cap; }; array, MAXV> G; array level, iter; void bfs(int s){ level.fill(-1); queue 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 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> B[i] >> C[i]; cin >> M; for(int i=0;i> D[i] >> E[i]; Dinic dinic; int s = 2 * N, t = s + 1; int res = 0; for(int i=0;i