#include<bits/stdc++.h> #define rep(i, l, r) for (int i = (l); i <= (r); ++i) #define per(i, l, r) for (int i = (l); i >= (r); --i) using std::cerr; using std::cin; using std::cout; using std::endl; using std::make_pair; using std::pair; typedeflonglong ll; typedefunsignedint ui; typedefunsignedlonglong ull; typedef pair<int, int> pii;
constint N = 200;
int r[N], b[N], p[N];
intmain(){ std::ios::sync_with_stdio(false); cout.tie(0); int n; cin >> n; rep(i, 1, n) cin >> r[i]; rep(i, 1, n) cin >> b[i]; int ge; bool flag = 0; int x = 0, y = 0, z; rep(i, 1, n){ if (r[i] == b[i]) { z++; continue; } if (r[i] == 1) x++; if (b[i] == 1) y++; } if (x == 0){ cout << -1; } else { if ((y+1)%x == 0) cout << (y+1)/x; else cout << (y+1)/x + 1; } return0; }
#include<bits/stdc++.h> #define rep(i, l, r) for (int i = (l); i <= (r); ++i) #define per(i, l, r) for (int i = (l); i >= (r); --i) using std::cerr; using std::cin; using std::cout; using std::endl; using std::make_pair; using std::pair; typedeflonglong ll; typedefunsignedint ui; typedefunsignedlonglong ull; typedef pair<int, int> pii;
#include<bits/stdc++.h> #define rep(i, l, r) for (int i = (l); i <= (r); ++i) #define per(i, l, r) for (int i = (l); i >= (r); --i) using std::cerr; using std::cin; using std::cout; using std::endl; using std::make_pair; using std::pair; typedeflonglong ll; typedefunsignedint ui; typedefunsignedlonglong ull; typedef pair<int, int> pii;
#include<bits/stdc++.h> #define rep(i, l, r) for (int i = (l); i <= (r); ++i) #define per(i, l, r) for (int i = (l); i >= (r); --i) using std::cerr; using std::cin; using std::cout; using std::endl; using std::make_pair; using std::pair; typedeflonglong ll; typedefunsignedint ui; typedefunsignedlonglong ull; typedef pair<int, int> pii;
namespace graph { constint INF = 2147483647; template <int N, int M> structgraph { structedge { int v, w; edge *nxt; edge() : v(0), w(0), nxt(NULL) {} edge(int _v, int _w, edge *_nxt) : v(_v), w(_w), nxt(_nxt) {} }; edge e[M]; edge *head[N]; int cnt, n; inlinevoidaddedge(constint &u, constint &v, constint w){ e[cnt] = edge(v, w, head[u]); head[u] = &e[cnt]; ++cnt; } graph() { std::memset(head, 0, sizeof(head)); cnt = 0; } voiddijkstra(int s, int dis[]){ for (int i = 0; i <= n; ++i) { dis[i] = INF; } std::priority_queue<pii, std::vector<pii>, std::greater<pii>> q; dis[s] = 0; q.push(std::make_pair(0, s)); while (!q.empty()) { pii cur = q.top(); q.pop(); if (cur.first > dis[cur.second]) continue; for (edge *i = head[cur.second]; i != NULL; i = i->nxt) { if (dis[i->v] > cur.first + i->w) { dis[i->v] = cur.first + i->w; q.push(std::make_pair(dis[i->v], i->v)); } } } } }; } // namespace graph
constint N = 2e5+100, M = 2e5+100;
graph::graph<N, M> f, g;
int p[N], dis[N];
intmain(){ std::ios::sync_with_stdio(false); cout.tie(0); int n, m; cin >> n >> m; f.n = g.n = n; rep(i, 1, m){ int u, v; cin >> u >> v; f.addedge(u, v, 1); g.addedge(v, u, 1); }
int k; cin >> k; rep(i, 1, k) cin >> p[i];
g.dijkstra(p[k], dis); int min = 0, max = 0; rep(qaq, 1, k-1){ int less = 0, eq = 0; int u = p[qaq]; int s = dis[p[qaq+1]]; for(auto i = f.head[u]; i ; i = i->nxt){ if (i->v == p[qaq+1]) continue; if (dis[i->v] < s) less++; if (dis[i->v] == s) eq++; } if (less) min++; if (less || eq) max++; } cout << min << ' ' << max; return0; }
#include<bits/stdc++.h> #define rep(i, l, r) for (int i = (l); i <= (r); ++i) #define per(i, l, r) for (int i = (l); i >= (r); --i) using std::cerr; using std::cin; using std::cout; using std::endl; using std::make_pair; using std::pair; typedeflonglong ll; typedefunsignedint ui; typedefunsignedlonglong ull; typedef pair<int, int> pii;
constint N = 1e6+10; ll inf = 0x3f3f3f3f3f3f3f3f;
int n, m; ll c;
structSeg{ structNode{ int l, r; ll sum, tag, max; } T[N*4]; #define s T[c] #define ls (c<<1) #define rs ((c<<1)|1) #define ln T[ls] #define rn T[rs] inlinevoidupd(int c){ s.sum = ln.sum + rn.sum; s.max = std::max(ln.max, rn.max); } inlinevoidpushdown(int c){ ln.tag += s.tag, rn.tag += s.tag; ln.sum += (ln.r-ln.l+1)*s.tag, rn.sum += (rn.r-rn.l+1)*s.tag; ln.max += s.tag, rn.max += s.tag; s.tag = 0; } voidbuild(int c, int l, int r){ s.l = l, s.r = r; if (l == r){ s.sum = s.max = -inf; return; } int mid = (l+r)/2; build(ls, l, mid); build(rs, mid+1, r); upd(c); } voidinit(int n){ build(1, 1, n); } int P, L, R; ll X; void _add(int c){ if (L <= s.l && s.r <= R){ s.tag += X; s.max += X; s.sum += (s.r-s.l+1)*X; return; } if (s.r < L || R < s.l) return; pushdown(c); _add(ls); _add(rs); upd(c); } voidadd(int pos, ll x){ L = R = pos, X = x; _add(1); } voidadd(int l, int r, ll x){ L = l, R = r, X = x; _add(1); } ll _query(int c){ if (L <= s.l && s.r <= R) return s.sum; if (s.r < L || R < s.l) return0; pushdown(c); return _query(ls) + _query(rs); } ll _query_max(int c){ if (L <= s.l && s.r <= R) return s.max; if (s.r < L || R < s.l) return -inf; pushdown(c); return std::max(_query_max(ls), _query_max(rs)); } ll query_max(int l, int r){ L=l, R=r; return _query_max(1); } ll query_sum(int l, int r){ L=l, R=r; return _query(1); } voidprint(int c){ cerr << s.l << ' ' << s.r << ' ' << s.max << endl; if (s.l == s.r){ return; } pushdown(c); print(ls); print(rs); } #undef s #undef ls #undef rs #undef ln #undef rn } ds;