正文
增加 9 行删除 9 行
18 行未改动19202122232425262728293031404 行未改动全部展开43643743843944044144244344492 行未改动5375385395405415425435445455465475485495505515525535545554 行未改动56056156256356456556656756843 行未改动61261361461561661761861962071 行未改动18 行未改动te w;int nxt;Edge() noexcept : v(0), w(0), nxt(-1) {}Edge(int _v, te _w, int _nxt) noexcept : v(_v), w(_w), nxt(_nxt) {}bool operator==(const Edge& other) const noexcept {return v == other.v && w == other.w;}bool operator!=(const Edge& other) const noexcept {return !(*this == other);}};404 行未改动全部展开:::info[代码]```c++std::vector<std::pair<te, bool>> dijkstra(int start) {std::vector<std::pair<te, bool>> state(head.size(), {0, false});if (start < 0 || start > (int)head.size()-1) {std::cerr << "Start vertex out of range!" << std::endl;state.assign(head.size(), {0, false});} else {92 行未改动:::info[代码]```c++std::pair<std::vector<std::pair<te, bool>>, bool> bellman_ford(int start, int count = -1) {std::vector<std::pair<te, bool>> state(size(), {0, false});if (start > -1 && start < size()) {state[start].first = 0;state[start].second = true;}int node_num = head.size();int relax_times = std::min((count == -1) ? (node_num - 1) : count, node_num - 1);bool has_negative_cycle = false;for (int round = 0; round < relax_times; ++round) {bool updated = false;std::vector<std::pair<te, bool>> prev_state = state;4 行未改动for (int e = head[u]; ~e; e = edges[e].nxt) {Edge edge = edges[e];te new_dist = prev_state[u].first + edge.w;if (!state[edge.v].second || new_dist < state[edge.v].first) {state[edge.v].first = new_dist;state[edge.v].second = true;updated = true;43 行未改动```c++std::pair<std::vector<te>, bool> spfa(int start) {int n = size();std::vector<te> dist(n, -1);std::vector<bool> in_queue(n, false);std::vector<int> in_cnt(n, 0);std::queue<int> q;dist[start] = 0;71 行未改动18 行未改动19202122232425262728293031404 行未改动全部展开43643743843944044144244344492 行未改动5375385395405415425435445455465475485495505515525535545554 行未改动56056156256356456556656756843 行未改动61261361461561661761861962071 行未改动18 行未改动te w;int nxt;Edge() noexcept : v(0), w(0), nxt(-1) {}Edge(int _v, te _w, int _nxt) noexcept : v(_v), w(_w), nxt(_nxt) {}bool operator==(const Edge& other) const noexcept {return v == other.v && w == other.w;}bool operator!=(const Edge& other) const noexcept {return !(*this == other);}};404 行未改动全部展开:::info[代码]```c++std::vector<std::pair<te, bool>> dijkstra(int start) {std::vector<std::pair<te, bool>> state(head.size(), {0, false});if (start < 0 || start > (int)head.size()-1) {std::cerr << "Start vertex out of range!" << std::endl;state.assign(head.size(), {0, false});} else {92 行未改动:::info[代码]```c++std::pair<std::vector<std::pair<te, bool>>, bool> bellman_ford(int start, int count = -1) {std::vector<std::pair<te, bool>> state(size(), {0, false});if (start > -1 && start < size()) {state[start].first = 0;state[start].second = true;}int node_num = head.size();int relax_times = std::min((count == -1) ? (node_num - 1) : count, node_num - 1);bool has_negative_cycle = false;for (int round = 0; round < relax_times; ++round) {bool updated = false;std::vector<std::pair<te, bool>> prev_state = state;4 行未改动for (int e = head[u]; ~e; e = edges[e].nxt) {Edge edge = edges[e];te new_dist = prev_state[u].first + edge.w;if (!state[edge.v].second || new_dist < state[edge.v].first) {state[edge.v].first = new_dist;state[edge.v].second = true;updated = true;43 行未改动```c++std::pair<std::vector<te>, bool> spfa(int start) {int n = size();std::vector<te> dist(n, -1);std::vector<bool> in_queue(n, false);std::vector<int> in_cnt(n, 0);std::queue<int> q;dist[start] = 0;71 行未改动