This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "Annalib.h"
#include <map>
#include <algorithm>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
map <pii, int> Mx;
ll in[305][305];
ll disa[305][305];
int reva[305][305];
void Anna(int N, int M, int A[], int B[], long long C[], int Q, int S[], int T[], int K, int U[]) {
int i, j, k;
for (i = 0; i < N; i++) for (j = 0; j < N; j++) if (i != j) disa[i][j] = LL_INF, reva[i][j] = i;
for (i = 0; i < M; i++) {
disa[A[i]][B[i]] = C[i];
reva[A[i]][B[i]] = A[i];
}
for (i = 0; i < K; i++) Mx[pii(A[U[i]], B[U[i]])] = i;
for (k = 0; k < N; k++) {
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
if (disa[i][j] > disa[i][k] + disa[k][j]) {
disa[i][j] = disa[i][k] + disa[k][j];
reva[i][j] = reva[k][j];
}
}
}
}
int c[6] = { 0, };
for (i = 0; i < Q; i++) {
int s = S[i], e = T[i];
int v = K;
while (e != s) {
int t = reva[s][e];
if (Mx.count(pii(t, e))) v = Mx[pii(t, e)];
e = t;
}
c[v]++;
}
for (i = 0; i <= K; i++) {
for (j = 5; j >= 0; j--) {
if (c[i] & (1 << j)) Tap(1);
else Tap(0);
}
}
}
#include "Brunolib.h"
#include <map>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll MOD2 = 1000000000000000000ll;
pll operator + (pll a, pll b) {
pll rv = pll(a.first + b.first, a.second + b.second);
if (rv.second >= MOD2) {
rv.first++;
rv.second -= MOD2;
}
return rv;
}
pll operator - (pll a, pll b) {
pll rv = pll(a.first - b.first, a.second - b.second);
if (rv.second < 0) {
rv.first--;
rv.second += MOD2;
}
return rv;
}
pll operator - (pll a) {
pll rv = pll(-a.first, -a.second);
if (rv.second < 0) {
rv.first--;
rv.second += MOD2;
}
return rv;
}
class edge {
public:
int s, e, f;
pll c;
edge() {
*this = edge(0, 0, 0, pll(0,0));
}
edge(int s, int e, int f, pll c) : s(s), e(e), f(f), c(c) {}
};
vector <edge> E;
vector <int> fconn[100050];
void epush(int s, int e, int f, pll c) {
edge e1 = edge(s, e, f, c);
edge e2 = edge(e, s, 0, -c);
fconn[s].push_back(E.size());
fconn[e].push_back(E.size() + 1);
E.push_back(e1);
E.push_back(e2);
}
pll fdis[100050];
int frev[100050];
bool fchk[100050];
vector <int> Vf;
ll totc = 0;
int BellmanFord(int snk) {
fill(fdis, fdis + snk + 1, pll(LL_INF, LL_INF));
fill(frev, frev + snk + 1, -1);
fill(fchk, fchk + snk + 1, false);
fchk[0] = true;
fdis[0] = pll(0, 0);
Vf.push_back(0);
for (int i = 0; i < Vf.size(); i++) {
fchk[Vf[i]] = false;
for (auto it : fconn[Vf[i]]) {
if (E[it].f == 0 || fdis[E[it].e] <= fdis[Vf[i]] + E[it].c) continue;
fdis[E[it].e] = fdis[Vf[i]] + E[it].c;
frev[E[it].e] = it;
if (!fchk[E[it].e]) {
Vf.push_back(E[it].e);
fchk[E[it].e] = true;
}
}
}
Vf.clear();
if (fdis[snk] == pll(LL_INF, LL_INF)) return 0;
int f = INF;
int t = snk;
while (t) {
f = min(f, E[frev[t]].f);
t = E[frev[t]].s;
}
t = snk;
while (t) {
E[frev[t]].f -= f;
E[frev[t] ^ 1].f += f;
t = E[frev[t]].s;
}
return f;
}
int getFlow(int snk) {
totc = 0;
int f = 0, t;
while (t = BellmanFord(snk)) f += t;
return f;
}
void init(int snk) {
for (int i = 0; i <= snk; i++) fconn[i].clear();
E.clear();
}
pll disb[305][305];
int revb[305][305];
pll getv(ll a) {
pll rv = pll(a / MOD2, a % MOD2);
if (rv.second < 0) {
rv.second += MOD2;
rv.first--;
}
return rv;
}
void getr(int s, int e, vector<int>& Vu) {
while (e != s) {
Vu.push_back(e);
e = revb[s][e];
}
Vu.push_back(s);
}
map <pii, int> Mxb;
void Bruno(int N, int M, int A[], int B[], long long C[], int Q, int S[], int T[], int K, int U[], int L, int X[]) {
int i, j, k;
for (i = 0; i < N; i++) for (j = 0; j < N; j++) if (i != j) disb[i][j] = getv(LL_INF), revb[i][j] = i;
for (i = 0; i < M; i++) Mxb[pii(A[i], B[i])] = i;
for (i = 0; i < M; i++) {
if (C[i] != -1) {
disb[A[i]][B[i]] = getv(C[i]);
revb[A[i]][B[i]] = A[i];
}
}
for (k = 0; k < N; k++) {
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
if (disb[i][j] > disb[i][k] + disb[k][j]) {
disb[i][j] = disb[i][k] + disb[k][j];
revb[i][j] = revb[k][j];
}
}
}
}
int v[6] = { 0, };
for (i = 0; i <= K; i++) {
for (j = 0; j < 6; j++) v[i] = 2 * v[i] + X[i * 6 + j];
}
ll src = 0, snk = Q + K + 2;
for (i = 0; i < Q; i++) {
for (j = 0; j <= K; j++) {
pll v = pll(0, 0);
if (j < K) v = (disb[S[i]][A[U[j]]] + disb[B[U[j]]][T[i]]) - disb[S[i]][T[i]];
epush(i + 1, Q + j + 1, 1, v);
}
}
for (i = 0; i < Q; i++) epush(src, i + 1, 1, getv(0));
for (i = 0; i <= K; i++) epush(Q + i + 1, snk, v[i], getv(0));
int f = getFlow(snk);
for (i = 0; i < Q; i++) {
for (j = 0; j <= K; j++) {
int p = (i * (K + 1) + j) * 2;
if (!E[p].f) break;
}
vector <int> Vu;
if (j == K) getr(S[i], T[i], Vu);
else {
getr(B[U[j]], T[i], Vu);
getr(S[i], A[U[j]], Vu);
}
reverse(Vu.begin(), Vu.end());
for (j = 0; j + 1 < Vu.size(); j++) Answer(Mxb[pii(Vu[j], Vu[j + 1])]);
Answer(-1);
}
}
Compilation message (stderr)
Bruno.cpp: In function 'int BellmanFord(int)':
Bruno.cpp:74:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < Vf.size(); i++) {
^
Bruno.cpp: In function 'int getFlow(int)':
Bruno.cpp:107:28: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
while (t = BellmanFord(snk)) f += t;
^
Bruno.cpp: In function 'void Bruno(int, int, int*, int*, long long int*, int, int*, int*, int, int*, int, int*)':
Bruno.cpp:187:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (j = 0; j + 1 < Vu.size(); j++) Answer(Mxb[pii(Vu[j], Vu[j + 1])]);
^
Bruno.cpp:173:6: warning: unused variable 'f' [-Wunused-variable]
int f = getFlow(snk);
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |