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 28, 2019
1 parent 549afc6 commit 7abd388
Show file tree
Hide file tree
Showing 5 changed files with 44,079 additions and 4 deletions.
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 = "theGreatEscape_UVA10967"; //*
const string CPPfile = "routeChange_UVA11833"; //*
//***************************************

ifstream fin(CPPfile + ".cpp");
Expand Down
71 changes: 68 additions & 3 deletions myCpps/routeChange_UVA11833.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,77 @@

using namespace std;

//ifstream fin("routeChange_UVA11833.in");
//ofstream fout("routeChange_UVA11833.out");
ifstream fin("routeChange_UVA11833.in");
ofstream fout("routeChange_UVA11833.out");

const int inf = INT_MAX / 3;

struct segment
{
int u;
int t;

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

int main()
{

while (true)
{
int n = 0, m = 0, cc = 0, kk = 0; fin >> n >> m >> cc >> kk;
if (n + m + cc + kk == 0) break;

vector<vector<int>> a(n, vector<int>(n, inf)),
g(n);
for (int c = 1; c <= m; ++c)
{
int u, v, t; fin >> u >> v >> t;
a[u][v] = t; a[v][u] = a[u][v];
g[u].push_back(v); g[v].push_back(u);
}

int temp = 0;
vector<int> d(cc, 0);
for (int u = cc - 2; u >= 0; --u)
{
temp += a[u][u + 1];
d[u] = temp;
}

vector<int> dp(n, inf);
priority_queue<segment> pq; pq.push(_segment(kk, 0));
while (pq.empty() == false)
{
segment now = pq.top(); pq.pop();

if (now.t >= dp[now.u]) continue;

dp[now.u] = now.t;

if (now.u <= cc - 1)
{
dp[cc - 1] = min(dp[cc - 1], now.t + d[now.u]);
continue;
}

int size = g[now.u].size();
for (int i = 0; i <= size - 1; ++i)
{
int v = g[now.u][i];

pq.push(_segment(v, now.t + a[now.u][v]));
}
}

fout << dp[cc - 1] << '\n';
}

return 0;
}
Loading

0 comments on commit 7abd388

Please sign in to comment.