Pagini recente » Cod sursa (job #3145515) | Clasamentul arhivei de probleme | Cod sursa (job #2463461) | Borderou de evaluare (job #2463670) | Cod sursa (job #2762755)
#include <bits/stdc++.h>
using namespace std;
using pi = pair<int, int>;
vector<pi> G[351];
int c[351][351], dd[351], inq[351], last[351], dp[351], dp2[351];
int main() {
ifstream cin("fmcm.in");
ofstream cout("fmcm.out");
int n, m, s, t, x, y, z, w;
cin >> n >> m >> s >> t;
while (m--) {
cin >> x >> y >> z >> w;
G[x].emplace_back(y, w);
G[y].emplace_back(x, -w);
c[x][y] = z;
}
int flow = 0, cost = 0;
queue<int> Q;
memset(dd, 0x3F, sizeof(dd));
inq[s] = 1;
dd[s] = 0;
while (!Q.empty()) {
int node = Q.front();
Q.pop();
inq[node] = 0;
for (auto x : G[node])
if (c[node][x.first] && dd[node] + x.second < dd[x.first]) {
dd[x.first] = dd[node] + x.second;
if (!inq[x.first]) {
inq[x.first] = 1;
Q.emplace(x.first);
}
}
}
//while (1) {
// auto comp = [&](pi a, pi b) {
// return a.second > b.second;
// };
// priority_queue<pi, vector<pi>, decltype(comp)> Q(comp);
// memset(last, 0xFF, sizeof(last));
// memset(dp, 0x3F, sizeof(dp));
// memset(dp2, 0, sizeof(dp2));
// Q.emplace(s, 0);
// dp[s] = 0;
// while (!Q.empty()) {
// int node, cost;
// tie(node, cost) = Q.top();
// Q.pop();
// if (dp[node] == cost)
// for (auto x : G[node]) {
// int fakecost = x.second + dd[node] - dd[x.first];
// if (c[node][x.first] && cost + fakecost < dp[x.first]) {
// last[x.first] = node;
// dp[x.first] = cost + fakecost;
// dp2[x.first] = dp2[node] + x.second;
// Q.emplace(x.first, cost + fakecost);
// }
// }
// }
// int curflow = INT_MAX;
// if (last[t] == -1)
// break;
// for (int i = t; i != s; i = last[i])
// curflow = min(curflow, c[last[i]][i]);
// for (int i = t; i != s; i = last[i]) {
// c[last[i]][i] -= curflow;
// c[i][last[i]] += curflow;
// }
// cost += dp2[t] * curflow;
// flow += curflow;
//}
//cout << cost << '\n';
}