Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int maxn = (int)1e5 + 10;
- vector <int> ed[maxn];
- int hospital(int city_nodes, vector<int> city_from, vector<int> city_to) {
- int n = city_nodes;
- for (int i = 0; i < (int)city_from.size(); i++) {
- int x = city_from[i];
- int y = city_to[i];
- x--;
- y--;
- ed[x].push_back(y);
- ed[y].push_back(x);
- }
- int ans = n;
- for (int ms = 0; ms < (1 << n); ms++) {
- int cur = 0;
- for (int i = 0; i < n; i++) {
- if ((ms >> i) & 1) {
- cur++;
- continue;
- }
- bool ok = false;
- for (int j = 0; j < (int)ed[i].size(); j++) {
- int to = ed[i][j];
- if ((ms >> to) & 1) {
- ok = true;
- break;
- }
- }
- if (!ok) {
- cur = n;
- break;
- }
- }
- ans = min(ans, cur);
- }
- return ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement