# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1054285 | 2024-08-12T08:25:32 Z | kiryl_krutsko | Swapping Cities (APIO20_swap) | C++14 | 0 ms | 0 KB |
#include <iostream> #include <vector> using namespace std; struct Min { int value = -1; int num; Min(int v, int n) { value = v; num = n; } }; bool isTree; vector<int> mins(3); vector<int> gas; void init(int n, int m, int e1[], int e2[], int g[]) { if (m != n - 1 || m == 2) { isTree = false; return; } isTree = true; for (auto M : mins) M = INT_MAX; for (int i = 0; i < m;i++) { gas.push_back(g[i]); if (g[i] < mins[0]) { mins.insert(mins.begin(), g[i]); mins.erase(mins.begin() + 3); } else if (g[i] < mins[1]) { mins.insert(mins.begin() + 1, g[i]); mins.erase(mins.begin() + 3); } else if (g[i] < mins[2]) { mins.insert(mins.begin() + 2, g[i]); mins.erase(mins.begin() + 3); } } } int getMinimumFuelCapacity(int x, int y) { if (!isTree) return -1; if (x == 0 || y == 0) { y = max(x, y); x = 0; if (gas[y] == mins[0]) return mins[1]; else return gas[y]; } if (gas[x] + gas[y] == mins[0] + mins[1]) { return mins[2]; } else return max(gas[x], gas[y]); }