cin >> a >> b >> c >> d; int find = 0, res = INT_MAX; for (int i = 0; i <= 100; i ++ ) for (int j = 0; j <= 100; j ++ ) { if ((b + i * a) == (d + j * c)) { find = 1; res = min(res, b + i * a); } } if (find) cout << res << '\n'; else cout << -1 << '\n'; return0; }
intmain(){ int n, m; cin >> n >> m; for (int i = 1; i <= n; i ++ ) cin >> a[i]; for (int j = 1; j <= m; j ++ ) cin >> b[j]; int i = 2, j = 2, step = 0; int sa = a[1], sb = b[1]; while (i <= n and j <= m) { if (sa == sb) { step ++ ; sa = 0, sb = 0; if (i <= n) { sa += a[i]; i ++ ; } if (j <= m) { sb += b[j]; j ++ ; } } elseif (sa < sb) { if (i <= n) { sa += a[i]; i ++ ; } } elseif (sa > sb) { if (j <= m) { sb += b[j]; j ++ ; } } } while (i <= n) sa += a[i ++ ]; while (j <= m) sb += b[j ++ ]; if (sa != sb) step = 0; elseif (sa) step ++ ; cout << step << '\n'; return0; }
usingnamespace std; using PII = pair<int, int>; constint N = 2e5 + 5;
vector<PII> g[N]; int f[N];
intdfs(int u, int fa){ int& ret = f[u]; for (auto& [v, w] : g[u]) { if (v == fa) continue; ret += dfs(v, u) + w; } return ret; }
voiddp(int u, int fa){ for (auto& [v, w] : g[u]) { if (v == fa) continue; if (w == 0) f[v] = f[u] + 1; else f[v] = f[u] - 1; dp(v, u); } }
intmain(){ int n; cin >> n; for (int i = 1; i < n; i ++ ) { int a, b; cin >> a >> b; g[a].push_back({b, 0}); g[b].push_back({a, 1}); } dfs(1, -1); dp(1, -1); int mn = INT_MAX; for (int i = 1; i <= n; i ++ ) mn = min(mn, f[i]); cout << mn << '\n'; for (int i = 1; i <= n; i ++ ) if (mn == f[i]) cout << i << ' '; cout << '\n'; return0; }