QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#51463 | #4479. Slipper | Winner | ML | 0ms | 0kb | C++11 | 1.9kb | 2022-10-02 14:49:02 | 2022-10-02 14:49:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, int> PLI;
typedef pair<int, ll> PIL;
#define x first
#define y second
const int N = 5e6 + 20;
const int mod = 998244353;
const int INF = 0x3f3f3f3f;
int n, k, p, s, t, maxd;
vector<PII> node[N];
ll dis[N];
bool vis[N];
void init(){
maxd = 0;
for(int i = 1; i <= 2 * n; i++){
node[i].clear();
}
}
void dfs(int u, int fa, int d){
for(auto [v, w]: node[u]){
if(v == fa) continue;
dfs(v, u, d + 1);
}
node[n + d].push_back({u, 0});
node[u].push_back({n + d, 0});
maxd = max(maxd, n + d);
}
void dijkstra(){
memset(dis, 0x3f, sizeof dis);
memset(vis, 0, sizeof vis);
priority_queue<PLI, vector<PLI>, greater<PLI> > q;
dis[s] = 0;
q.push({0, s});
while(!q.empty()){
auto it = q.top();
q.pop();
ll nowdis = it.x;
int nowid = it.y;
if(vis[nowid]) continue;
vis[nowid] = true;
for(auto [v, w]: node[nowid]){
if(vis[v]) continue;
if(nowdis + w < dis[v]){
dis[v] = min(dis[v], nowdis + w);
q.push({dis[v], v});
}
}
}
}
void solve(){
scanf("%d", &n);
init();
for(int i = 1; i < n; i++){
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
node[u].push_back({v, w});
node[v].push_back({u, w});
}
dfs(1, -1, 1);
scanf("%d%d", &k, &p);
for(int i = 1; i <= n; i++){
if(n + i + k > maxd)
break;
node[n + i].push_back({n + i + k, p});
node[n + i + k].push_back({n + i, p});
}
scanf("%d%d", &s, &t);
dijkstra();
printf("%lld\n", dis[t]);
}
int main(){
int T = 1;
scanf("%d", &T);
while(T--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Memory Limit Exceeded
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...