#include <bits/stdc++.h>
using namespace std;
#define int long long
long long cost[101][20006];
vector<pair<int,pair<int,int>>> adj[201];
signed main(){
int n,m;
cin>>n>>m;
for(int i = 0;i<=n;i++){
for(int j = 1;j<=20000;j++){
cost[i][j] = 1e10;
}
}
for(int i = 0;i<m;i++){
int a,b,c,d;
cin>>a>>b>>c>>d;
adj[a].push_back({b,{c,d}});
adj[b].push_back({a,{c,d}});
}
priority_queue<pair<int,pair<int,int>>> q;
q.push({0,{0,1}});
cost[1][0]=0;
while(!q.empty()){
int no = q.top().second.second;
int se = q.top().second.first;
int co = -q.top().first;
q.pop();
if(cost[no][se]<co)continue;
for(auto j:adj[no]){
if(cost[j.first][se+j.second.first]>co+j.second.second){
cost[j.first][se+j.second.first] = co+j.second.second;
q.push({-cost[j.first][se+j.second.first],{se+j.second.first,j.first}});
}
}
}
for(int i = 2;i<=n;i++){
long long ans = 1e18;
for(long long j = 1;j<=20000;j++){
//if(i==n)cout<<cost[i][j]<<" ";
ans = min(ans,j*cost[i][j]);
}
if(ans>=1e9)cout<<"-1"<<endl;
else cout<<ans<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
2132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
507 ms |
40548 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
279 ms |
8776 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
402 ms |
38848 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
27 ms |
32468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
23 ms |
32496 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
22 ms |
32464 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
25 ms |
32404 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
22 ms |
32460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
21 ms |
32376 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |