#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define em emplace
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const int MAX = 3030;
const int INF = 1e9;
const ll LINF = 1e18;
ll c[MAX];
int n, m;
vector <pair <int, ll> > g[MAX], ng[MAX];
void djikstra(int v) {
vector <ll> d(n+1);
vector <bool> chk(n+1);
for(int i = 1; i <= n; i++) {
d[i] = LINF;
}
d[v] = 0;
priority_queue <pll, vector <pll>, greater <pll> > pq;
pq.em(0, v);
while(!pq.empty()) {
int x = pq.top().se;
pq.pop();
if(chk[x]) continue;
chk[x] = true;
for(auto i : g[x]) {
int y = i.fi;
if(d[y] > d[x] + i.se) {
d[y] = d[x] + i.se;
pq.em(d[y], y);
}
}
}
for(int i = 1; i <= n; i++) {
if(i == v) continue;
ng[v].eb(i, c[v] * d[i]);
}
}
void ndjikstra(int v) {
vector <ll> d(n+1);
vector <bool> chk(n+1);
for(int i = 1; i <= n; i++) {
d[i] = LINF;
}
d[v] = 0;
priority_queue <pll, vector <pll>, greater <pll> > pq;
pq.em(0, v);
while(!pq.empty()) {
int x = pq.top().se;
pq.pop();
if(chk[x]) continue;
chk[x] = true;
for(auto i : ng[x]) {
int y = i.fi;
if(d[y] > d[x] + i.se) {
d[y] = d[x] + i.se;
pq.em(d[y], y);
}
}
}
cout << d[n];
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> c[i];
}
for(int i = 1; i <= m; i++) {
int u, v, w;
cin >> u >> v >> w;
g[u].eb(v, w), g[v].eb(u, w);
}
for(int i = 1; i <= n; i++) {
djikstra(i);
}
ndjikstra(1);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
0 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
135 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
133 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
0 ms |
460 KB |
Output is correct |
14 |
Correct |
13 ms |
4556 KB |
Output is correct |
15 |
Correct |
14 ms |
4544 KB |
Output is correct |
16 |
Correct |
13 ms |
4480 KB |
Output is correct |
17 |
Correct |
53 ms |
4592 KB |
Output is correct |
18 |
Correct |
53 ms |
4572 KB |
Output is correct |
19 |
Correct |
26 ms |
4388 KB |
Output is correct |
20 |
Correct |
28 ms |
4420 KB |
Output is correct |
21 |
Correct |
25 ms |
4428 KB |
Output is correct |
22 |
Correct |
25 ms |
4424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
0 ms |
460 KB |
Output is correct |
14 |
Runtime error |
135 ms |
65540 KB |
Execution killed with signal 9 |
15 |
Halted |
0 ms |
0 KB |
- |