Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
gzshawnliang committed Jul 13, 2019
1 parent d8156f4 commit 6930073
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"**/.factorypath": true
},
// "C_Cpp.intelliSenseEngineFallback": "Disabled",
"C_Cpp.errorSquiggles":"Disabled",
"C_Cpp.errorSquiggles":"Enabled",

"java.debug.settings.enableRunDebugCodeLens": false,
"java.debug.settings.forceBuildBeforeLaunch":false,
Expand Down
2 changes: 1 addition & 1 deletion myCpps/!-OJcreater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using namespace std;

//***************************************
const string CPPfile = "fromDuskTillDawn_UVA10187"; //*
const string CPPfile = "almostShortestPath_UVA12144"; //*
//***************************************

ifstream fin(CPPfile + ".cpp");
Expand Down
106 changes: 50 additions & 56 deletions myCpps/almostShortestPath_UVA12144.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ const int inf = INT_MAX / 2;
struct segment
{
int u;
int lastU;
int p;

bool operator < (const segment & temp) const
{
return p > temp.p;
}
};
segment _segment(int u, int lastU, int p)
segment _segment(int u, int p)
{
segment temp{u, lastU, p}; return temp;
segment temp{u, p}; return temp;
}

struct edge
Expand All @@ -33,6 +32,17 @@ edge _edge(int u, int v)
edge temp{u, v}; return temp;
}

void erasePath(int u, vector<vector<int>> & a, vector<set<int>> & f)
{
for (auto it = f[u].begin(); it != f[u].end(); ++it)
{
int v = *it;

a[v][u] = inf;
erasePath(v, a, f);
}
}

int main()
{
while (true)
Expand All @@ -50,84 +60,68 @@ int main()
a[u][v] = p;
}

bool isFirstS = true;
vector<int> pMin(n, inf); pMin[s] = 0;
priority_queue<segment> pq; pq.push(_segment(s, -1, 0));
vector<int> d(n, inf);
priority_queue<segment> pq; pq.push(_segment(s, 0));
vector<set<int>> f(n);
while (pq.empty() == false)
{
segment now = pq.top(); pq.pop();

if (now.p >= pMin[now.u] && isFirstS == false) continue;
isFirstS = false;
pMin[now.u] = now.p;

for (int v = 0; v <= n - 1; ++v)
{
if (now.u != v && a[now.u][v] < inf)
if (a[now.u][v] == inf) continue;

segment next;
next.u = v;
next.p = now.p + a[now.u][v];

if (next.p < d[next.u])
{
d[next.u] = next.p;
f[v].clear();
f[v].insert(now.u);

pq.push(next);
}
else if (next.p == d[next.u])
{
pq.push(_segment(v, now.u, now.p + a[now.u][v]));
f[v].insert(now.u);
}
}
}

int ans = pMin[e];
while (ans == pMin[e])
f[s].clear();
erasePath(e, a, f);

vector<int> _d(n, inf);
priority_queue<segment> _pq; _pq.push(_segment(s, 0));
while (_pq.empty() == false)
{
for (int u = 0; u <= n - 1; ++u)
{
for (int v = u + 1; v <= n - 1; ++v)
{
if (a[u][v] < inf)
{
fout << u << "-->" << v << ": " << a[u][v] << '\n';
}
if (a[v][u] < inf)
{
fout << v << "-->" << u << ": " << a[v][u] << '\n';
}
}
}
segment now = _pq.top(); _pq.pop();

bool isFirstS_t = true;
vector<int> f(n, -1), pMin_t(n, inf); pMin_t[s] = 0;
priority_queue<segment> pq_t; pq_t.push(_segment(s, -1, 0));
while (pq_t.empty() == false)
for (int v = 0; v <= n - 1; ++v)
{
segment now = pq_t.top(); pq_t.pop();
if (a[now.u][v] == inf) continue;

if (now.p >= pMin_t[now.u] && isFirstS_t == false) continue;
isFirstS_t = false;
pMin_t[now.u] = now.p;
f[now.u] = now.lastU;
segment next;
next.u = v;
next.p = now.p + a[now.u][v];

for (int v = 0; v <= n - 1; ++v)
if (next.p < _d[next.u])
{
if (now.u != v && a[now.u][v] < inf)
{
pq_t.push(_segment(v, now.u, now.p + a[now.u][v]));
}
}
}

ans = pMin_t[e];

int _u = e;
while (f[_u] >= 0)
{
a[f[_u]][_u] = inf;
_u = f[_u];
_d[next.u] = next.p;
_pq.push(next);
}
}

fout << ans << '\n';
}

if (ans == inf)
if (_d[e] == inf)
{
fout << "-1\n";
}
else
{
fout << ans << '\n';
fout << _d[e] << '\n';
}
}

Expand Down
18 changes: 9 additions & 9 deletions myCpps/almostShortestPath_UVA12144.in
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
6 7
0 5
0 1 1
1 2 1
2 3 1
0 3 3
3 4 1
4 5 1
3 5 1
5 7
0 2
0 4 5
0 3 5
0 1 10
4 1 1
3 4 6
2 0 8
4 2 4
0 0
16 changes: 1 addition & 15 deletions myCpps/almostShortestPath_UVA12144.out
Original file line number Diff line number Diff line change
@@ -1,15 +1 @@
0-->1: 1
0-->3: 3
1-->2: 1
2-->3: 1
3-->4: 1
3-->5: 1
4-->5: 1
4
0-->1: 1
1-->2: 1
2-->3: 1
3-->4: 1
4-->5: 1
5
5
-1
3 changes: 2 additions & 1 deletion other/thomas/dijkstra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class dijkstra
reverse(i.begin(), i.end());
multiPath2.push_back(i);
}
return multiPath2;
return
;
}

void RunNoPath(int s)
Expand Down

0 comments on commit 6930073

Please sign in to comment.