QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#593077 | #6845. Tax | Sound_Medium | RE | 0ms | 3848kb | C++23 | 1.4kb | 2024-09-27 11:28:35 | 2024-09-27 11:28:35 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define PII pair<int,int>
int n, m;
void solve () {
cin>>n>>m;
vector<int>gs(m+1,0);
vector<int>a(n+1,0);
vector<vector<pair<int,int>>>g(n+1);
for(int i=1;i<=m;i++)cin>>a[i];
while(m--){
int u,v,w;
cin>>u>>v>>w;
g[u].push_back({v,w});
g[v].push_back({u,w});
}
vector<int>dis(n+1,1e18);
vector<int>cost(n+1,1e18);
dis[1]=0;
queue<int>q;
// priority_queue<PII,vector<PII>,greater<PII>>q;
q.push(1);
cost[1]=0;
while(q.size()){
auto u=q.front();
q.pop();
for(auto [v,w]:g[u]){
if(dis[v]>dis[u]+1){
dis[v]=dis[u]+1;
q.push(v);
}
}
}
auto dfs=[&](auto &&self,int u,int dist)->void{
{}
for(auto [v,w]:g[u]){
if(dist+1!=dis[v])continue;
gs[w]++;
if(cost[v]>cost[u]+gs[w]*a[w]){
cost[v]=cost[u]+gs[w]*a[w];
}
self(self,v,dist+1);
gs[w]--;
}
};
dfs(dfs,1,0);
for(int i=2;i<=n;i++){
cout<<cost[i]<<"\n";
}
}
signed main () {
int T = 1;
std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
//cin>>T;
while (T --) solve ();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
input:
5 6 1 8 2 1 3 9 1 2 1 2 3 2 1 4 1 3 4 6 3 5 4 4 5 1
output:
1 9 1 3
result:
ok 4 lines
Test #2:
score: -100
Runtime Error
input:
10 15 730 2163 6818 4647 9699 1037 2034 8441 2619 6164 464 4369 4500 6675 1641 1 6 2 3 6 1 3 2 1 9 2 2 7 3 1 6 5 1 5 3 2 3 10 1 10 2 2 5 10 1 8 2 2 9 8 1 7 4 2 4 5 2 4 10 2