QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#60588 | #4479. Slipper | qinjianbin# | AC ✓ | 1545ms | 220952kb | C++17 | 1.5kb | 2022-11-05 16:45:48 | 2022-11-05 16:45:50 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define _for(i, a, b) for(int i = (a); i <= (b); i++)
using namespace std;
typedef long long ll;
const int N = 2e6 + 10;
ll d[N];
struct node
{
int v; ll w;
bool operator < (const node& rhs) const
{
return w > rhs.w;
}
};
vector<pair<int, int>> g[N];
vector<int> ve[N];
int n, k, p, s, t, cnt;
void dfs(int u, int fa, int dep)
{
ve[dep].push_back(u);
for(auto [v, w]: g[u])
{
if(v == fa) continue;
dfs(v, u, dep + 1);
}
}
void solve()
{
_for(i, 1, 2 * n) d[i] = 1e18;
d[s] = 0;
priority_queue<node> q;
q.push({s, d[s]});
while(!q.empty())
{
node x = q.top(); q.pop();
int u = x.v;
if(d[u] != x.w) continue;
for(auto [v, w]: g[u])
if(d[v] > d[u] + w)
{
d[v] = d[u] + w;
q.push({v, d[v]});
}
}
}
int main()
{
int T; scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
_for(i, 1, 2 * n) g[i].clear(), ve[i].clear();
_for(i, 1, n - 1)
{
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
g[u].push_back({v, w});
g[v].push_back({u, w});
}
scanf("%d%d%d%d", &k, &p, &s, &t);
dfs(1, 0, 1);
cnt = n;
_for(i, 1, n)
{
if(!ve[i].size()) break;
cnt++;
for(int x: ve[i]) g[x].push_back({cnt, 0});
for(int x: ve[i + k]) g[cnt].push_back({x, p});
if(i - k >= 1) for(int x: ve[i - k]) g[cnt].push_back({x, p});
}
solve();
printf("%lld\n", d[t]);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1545ms
memory: 220952kb
input:
5 121753 103252 40559 325002 32674 51809 946614 18343 12099 625962 27677 48601 114048 11146 12478 906161 121147 77390 208299 39512 95642 154696 90603 43508 378490 4829 7818 191754 73699 31412 536840 106916 89894 374802 113739 90049 411062 113123 73246 740213 38047 120942 903325 51907 41500 822541 90...
output:
114128108 55207815 76620494 17377950755 67601
result:
ok 5 lines