Correctin: BSB; but it's quite slow.

This commit is contained in:
2025-11-28 08:01:39 +09:00
parent fcf4199c06
commit 2011104d10
3 changed files with 38 additions and 13 deletions

View File

@@ -26,7 +26,7 @@ BUILD_OUT_B_DIR = $(BUILD_DIR)/$(SOL_B)_out
DIRS = $(BUILD_DIR) $(BUILD_TARGET_DIR) $(BUILD_GEN_DIR) $(BUILD_VAL_DIR) $(BUILD_CHK_DIR) $(LOG_DIR) $(BUILD_IN_DIR) $(BUILD_OUT_A_DIR) $(BUILD_OUT_B_DIR) $(BUILD_TEST_DIR) DIRS = $(BUILD_DIR) $(BUILD_TARGET_DIR) $(BUILD_GEN_DIR) $(BUILD_VAL_DIR) $(BUILD_CHK_DIR) $(LOG_DIR) $(BUILD_IN_DIR) $(BUILD_OUT_A_DIR) $(BUILD_OUT_B_DIR) $(BUILD_TEST_DIR)
CXXFLAGS = -Wall -O2 -std=c++2a CXXFLAGS = -Wall -O3 -std=c++2a
GENFLAGS = -N $(N) -M $(M) -pm $(pm) GENFLAGS = -N $(N) -M $(M) -pm $(pm)
SRC_MAIN_FILES = $(wildcard $(SRC_DIR)/*/main.cpp) SRC_MAIN_FILES = $(wildcard $(SRC_DIR)/*/main.cpp)
@@ -66,7 +66,7 @@ $(BUILD_DIR) $(BUILD_TARGET_DIR) $(BUILD_GEN_DIR) $(BUILD_VAL_DIR) $(BUILD_CHK_D
$(BUILD_TARGET_DIR)/%: $(SRC_DIR)/%/main.cpp | $(BUILD_TARGET_DIR) $(BUILD_TARGET_DIR)/%: $(SRC_DIR)/%/main.cpp | $(BUILD_TARGET_DIR)
@echo "Compiling Solution $< -> $@" @echo "Compiling Solution $< -> $@"
$(CXX) $(CXXFLAGS) -fsanitize=undefined,address -o $@ $< $(CXX) $(CXXFLAGS) -o $@ $<
$(BUILD_GEN_DIR)/%: $(GEN_DIR)/%.cpp | $(BUILD_GEN_DIR) $(BUILD_GEN_DIR)/%: $(GEN_DIR)/%.cpp | $(BUILD_GEN_DIR)
@echo "Compiling Generator $< -> $@" @echo "Compiling Generator $< -> $@"

View File

@@ -20,6 +20,13 @@ namespace GMS {
using namespace std; using namespace std;
using ll = unsigned long long; using ll = unsigned long long;
using DIST = tuple<double, ll, ll>;
ostream& operator<<(ostream& os, DIST& dist)
{
os<<'(' << get<0>(dist) << ' ' << get<1>(dist) << ' ' << get<2>(dist) << ')';
return os;
}
template <typename KEY, typename VALUE> template <typename KEY, typename VALUE>
class L33 { class L33 {
private: private:
@@ -56,20 +63,20 @@ class L33 {
assert(!b || it_B->second == b.value()); assert(!b || it_B->second == b.value());
it_BLIST->erase(it_B); it_BLIST->erase(it_B);
if (it_BLIST->size() == 0) { if (it_BLIST->size() == 0 && UB[B] != it_ILIST) {
blocks.erase(it_BLIST); blocks.erase(it_BLIST);
if (d01 == 0) if (d01 == 0)
D0.erase(it_ILIST); D0.erase(it_ILIST);
else { else if(d01 == 1){
UB.erase(it_ILIST->first); UB.erase(it_ILIST->first);
D1.erase(it_ILIST); D1.erase(it_ILIST);
if (D1.empty()) { // if (D1.empty()) {
auto it_BLIST = blocks.emplace(blocks.end()); // auto it_BLIST = blocks.emplace(blocks.end());
auto it_ILIST = D1.emplace(D1.end(), B, it_BLIST); // auto it_ILIST = D1.emplace(D1.end(), B, it_BLIST);
UB[B] = it_ILIST; // UB[B] = it_ILIST;
} // }
} }
} }
} }

View File

@@ -93,7 +93,7 @@ pair<DIST, unordered_set<ll> > BMSSP(ll l, vector<ll> S, DIST B,
const ll k, const ll t) { const ll k, const ll t) {
assert(S.size() <= (1uLL << (l * t))); assert(S.size() <= (1uLL << (l * t)));
// cerr<<"LEVLE "<<l<<endl; // cerr<<"LEVEL "<<l<<endl;
// cerr<<"S: "; for(auto i:S) cerr<<i<<' '; cerr<<endl; // cerr<<"S: "; for(auto i:S) cerr<<i<<' '; cerr<<endl;
if (l == 0) { if (l == 0) {
@@ -146,24 +146,33 @@ pair<DIST, unordered_set<ll> > BMSSP(ll l, vector<ll> S, DIST B,
// for(auto i:W) cerr<<i<<' '; // for(auto i:W) cerr<<i<<' ';
// cerr<<endl; // cerr<<endl;
// cerr<<get<0>(B)<<' '<<get<1>(B)<<' '<<get<2>(B)<<endl; // cerr<<B<<endl;
L33<ll, DIST> D(M, B); L33<ll, DIST> D(M, B);
for (auto i : P) D.Insert(i, dist[i]); for (auto i : P) D.Insert(i, dist[i]);
// D._debug(std::cerr);
const ll LIMIT = k * (1uLL << (l * t)); const ll LIMIT = k * (1uLL << (l * t));
// cerr<<"LIMIT: "<<LIMIT<<endl; // cerr<<"LIMIT: "<<LIMIT<<endl;
unordered_set<ll> U; unordered_set<ll> U;
DIST B_; DIST B_ = B;
while (U.size() < LIMIT && !D.empty()) { while (U.size() < LIMIT && !D.empty()) {
auto [Bi, Si] = D.Pull(); auto [Bi, Si] = D.Pull();
// cerr<<get<0>(Bi)<<' '<<get<1>(Bi)<<' '<<get<2>(Bi)<<endl; // cerr<<get<0>(Bi)<<' '<<get<1>(Bi)<<' '<<get<2>(Bi)<<endl;
// cerr<<"Si: "; for(auto i:Si) cerr<<i<<' '; cerr<<endl; // cerr<<"Si: "; for(auto i:Si) cerr<<i<<' '; cerr<<endl;
// cerr<<"I'm LEVEL "<<l<<endl;
// cerr<<"S: "; for(auto i:S) cerr<<i<<' '; cerr<<endl;
// cerr<<"goto BMSSP("<<l-1<<", Si, "<<Bi<<", *, *, "<<k<<", "<<t<<");"<<endl;
// cerr<<"Si: "; for(auto i:Si) cerr<<i<<' '; cerr<<endl;
auto [Bi_, Ui] = BMSSP(l - 1, Si, Bi, adj, dist, k, t); auto [Bi_, Ui] = BMSSP(l - 1, Si, Bi, adj, dist, k, t);
B_ = Bi_; B_ = Bi_;
// cerr<<"received B_: "<<B_<<endl;
// cerr<<"received Ui: "; for(auto i:Ui) cerr<<i<<' '; cerr<<endl;
// cerr<<get<0>(Bi_)<<' '<<get<1>(Bi_)<<' '<<get<2>(Bi_)<<endl; // cerr<<get<0>(Bi_)<<' '<<get<1>(Bi_)<<' '<<get<2>(Bi_)<<endl;
// cerr<<"Ui: "; for(auto i:Ui) cerr<<i<<' '; cerr<<endl; // cerr<<"Ui: "; for(auto i:Ui) cerr<<i<<' '; cerr<<endl;
@@ -176,7 +185,12 @@ pair<DIST, unordered_set<ll> > BMSSP(ll l, vector<ll> S, DIST B,
if (relex(u, dist[u], len, v, dist[v])) { if (relex(u, dist[u], len, v, dist[v])) {
// cerr<<"OK!"<<endl; // cerr<<"OK!"<<endl;
if (Bi <= dist[v] && dist[v] < B) if (Bi <= dist[v] && dist[v] < B)
{
// cerr<<"[!] INSERT: "<<v<<' '<<dist[v]<<endl;
// D._debug(cerr);
D.Insert(v, dist[v]); D.Insert(v, dist[v]);
// D._debug(cerr);
}
else if (Bi_ <= dist[v] && dist[v] < Bi) else if (Bi_ <= dist[v] && dist[v] < Bi)
K.insert(v); K.insert(v);
} }
@@ -193,7 +207,11 @@ pair<DIST, unordered_set<ll> > BMSSP(ll l, vector<ll> S, DIST B,
// for(auto [s, _]: K_) cerr<<s<<' '; // for(auto [s, _]: K_) cerr<<s<<' ';
// cerr<<endl; // cerr<<endl;
// cerr<<"[!A]"<<endl;
// D._debug(std::cerr);
D.BatchPrepend(K_); D.BatchPrepend(K_);
// cerr<<"[!B]"<<endl;
// D._debug(std::cerr);
} }
B_ = min(B_, B); B_ = min(B_, B);