QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#207060 | #7404. Back and Forth | RedDiamond | WA | 0ms | 3656kb | C++23 | 1.5kb | 2023-10-08 05:40:48 | 2023-10-08 05:40:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200 + 7;
const int INF = (int) 1e9;
int p[N];
int dist[N][N];
int n, m, s, t;
struct Edge {
int x;
int y;
int v;
};
bool operator < (Edge a, Edge b) {
return a.v > b.v;
}
bool vis[N][N];
void solve() {
cin >> n >> m >> s >> t;
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
dist[i][j] = INF;
vis[i][j] = 0;
}
}
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
dist[x][y] = p[y];
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
priority_queue<Edge> pq;
pq.push({s, s, p[s]});
while (!pq.empty()) {
Edge e = pq.top();
pq.pop();
if (vis[e.x][e.y]) continue;
vis[e.x][e.y] = 1;
if (e.x == t && e.y == t) {
cout << e.v << "\n";
return;
}
if (!vis[e.y][e.x]) {
pq.push({e.y, e.x, e.v + dist[e.x][e.y] - p[e.x]});
}
for (int k = 1; k <= n; k++) {
pq.push({k, e.y, e.v + dist[e.x][k] - p[k] * (e.y == k)});
pq.push({e.x, k, e.v + dist[k][e.y] - p[k] * (e.x == k)});
}
}
}
signed main() {
#ifdef ONPC
freopen("input.txt", "r", stdin);
#else
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif // ONPC
int tt;
cin >> tt;
while (tt--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3652kb
input:
3 4 5 1 4 1 1 1 1 1 2 2 3 3 1 4 2 3 4 4 4 1 2 1 1 1 1 1 2 2 3 3 4 4 1 4 8 1 3 1 100 1 1 1 2 2 1 2 3 3 2 1 4 4 1 3 4 4 3
output:
4 4 3
result:
ok 3 number(s): "4 4 3"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3656kb
input:
1 2 0 1 2 1 1
output:
2000000000
result:
wrong answer 1st numbers differ - expected: '-1', found: '2000000000'