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<bits/stdc++.h>
using namespace std;
#include "Annalib.h"
#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;
template<class T>
inline bool asMn(T &a, const T &b) { return a > b ? a = b, true : false; }
template<class T>
inline bool asMx(T &a, const T &b) { return a < b ? a = b, true : false; }
const LL infLL = 4e18;
void tap(int x) {
static int cnt = 0;
if (cnt == 64) return ;
++cnt;
Tap(x);
}
void Anna(int N, int M, int A[], int B[], LL C[], int Q, int S[], int T[], int K, int U[]) {
vector<vector<LL> > d(N, vector<LL>(N, infLL) );
for (int u = 0; u < N; ++u) d[u][u] = 0;
for (int i = 0; i < M; ++i) d[ A[i] ][ B[i] ] = C[i];
for (int i = 0; i < K; ++i) d[ A[ U[i] ] ][ B[ U[i] ] ] = infLL;
for (int w = 0; w < N; ++w) {
for (int u = 0; u < N; ++u) {
for (int v = 0; v < N; ++v) {
asMn(d[u][v], d[u][w] + d[w][v]);
}
}
}
vector<int> group(Q, -1);
vector<LL> ans(Q);
for (int i = 0; i < Q; ++i) ans[i] = d[ S[i] ][ T[i] ];
for (int i = 0; i < K; ++i) {
vector<int> cnt(i + 1);
for (int j = 0; j <= i; ++j) cnt[j] = count(all(group), j - 1);
vector<int> cnt2(i + 1);
for (int j = 0; j < Q; ++j) if (asMn(ans[j], C[ U[i] ] + d[ S[j] ][ A[ U[i] ] ] + d[ B[ U[i] ] ][ T[j] ]) ) {
++cnt2[ group[j] + 1 ];
group[j] = i;
}
int lim = 1, tmp = 0;
for (int j = 0; j <= i; ++j) {
lim *= cnt[j] + 1;
tmp *= cnt[j] + 1; tmp += cnt2[j];
}
for (int j = __lg(lim - 1); ~j; --j) tap(tmp >> j & 1);
}
}
#include<bits/stdc++.h>
using namespace std;
#include "Brunolib.h"
#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;
template<class T>
inline bool asMn(T &a, const T &b) { return a > b ? a = b, true : false; }
template<class T>
inline bool asMx(T &a, const T &b) { return a < b ? a = b, true : false; }
const LL infLL = 4e18;
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[]) {
vector<vector<LL> > d(N, vector<LL>(N, infLL) ),
trace(N, vector<LL>(N, -1) );
for (int u = 0; u < N; ++u) d[u][u] = 0;
for (int i = 0; i < M; ++i) {
d[ A[i] ][ B[i] ] = C[i];
trace[ A[i] ][ B[i] ] = i;
}
for (int i = 0; i < K; ++i) {
d[ A[ U[i] ] ][ B[ U[i] ] ] = infLL;
trace[ A[ U[i] ] ][ B[ U[i] ] ] = -1;
}
for (int w = 0; w < N; ++w) {
for (int u = 0; u < N; ++u) {
for (int v = 0; v < N; ++v) {
if (asMn(d[u][v], d[u][w] + d[w][v]) ) trace[u][v] = trace[u][w];
}
}
}
auto get = [&](int iQ, int i, int j) {
return d[ S[iQ] ][ A[ U[j] ] ] + d[ B[ U[j] ] ][ T[iQ] ]
- (~i ? d[ S[iQ] ][ A[ U[i] ] ] + d[ B[ U[i] ] ][ T[iQ] ] : d[ S[iQ] ][ T[iQ] ]);
};
vector<int> group(Q, -1);
for (int i = 0, iX = 0; i < K; ++i) {
vector<vector<int> > iQ(i + 1);
for (int j = 0; j < Q; ++j) iQ[ group[j] + 1 ].emplace_back(j);
for (auto &j : iQ) {
sort(all(j), [&](const int &a, const int &b) {
return get(a, group[a], i) < get(b, group[b], i);
});
}
vector<int> cnt(i + 1);
int lim = 1;
for (int j = 0; j <= i; ++j) {
cnt[j] = (int)count(all(group), j - 1);
lim *= cnt[j] + 1;
}
int receive = 0;
for (int j = __lg(lim - 1); ~j; --j) if (X[iX++]) receive |= 1 << j;
vector<int> tmp(i + 1);
for (int j = i; ~j; --j) {
tmp[j] = receive % (cnt[j] + 1);
receive /= cnt[j] + 1;
}
for (int j = 0; j <= i; ++j) {
for (int k = 0; k < tmp[j]; ++k) group[ iQ[j][k] ] = i;
}
}
function<void(int, int)> answer = [&](int u, int v) {
if (u == v) return ;
Answer(trace[u][v]);
answer(B[ trace[u][v] ], v);
};
for (int i = 0; i < Q; ++i) {
if (~group[i]) {
answer(S[i], A[ U[ group[i] ] ]);
Answer(U[ group[i] ]);
answer(B[ U[ group[i] ] ], T[i]);
}
else answer(S[i], T[i]);
Answer(-1);
}
}
# | 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... |