This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#define N 2500
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
int ej[N][N], ew[N][N], eo[N];
void append(int i, int j, int w) {
ej[i][eo[i]] = j, ew[i][eo[i]] = w, eo[i]++;
}
char visited[N]; int t, d_, w_;
int dfs(int i, int d) {
int o;
if (visited[i])
return 0;
visited[i] = 1;
for (o = eo[i]; o--; ) {
int j = ej[i][o], w = ew[i][o];
if (j == t) {
d_ = d + w, w_ = w;
return 1;
}
if (dfs(j, d + w))
return 1;
}
return 0;
}
int main() {
int n, m, s, h, i, j, w, d1, w1, d2, w2;
scanf("%d%d%d%d", &n, &m, &s, &t), s--, t--;
for (h = 0; h < m; h++) {
scanf("%d%d%d", &i, &j, &w), i--, j--;
append(i, j, w), append(j, i, w);
}
visited[s] = 0, dfs(-1, s), d1 = d_, w1 = w_;
visited[s] = 0, dfs(-1, s), d2 = d_, w2 = w_;
printf("%d\n", min(max(d1, d2 + (d1 - w1) * 2), max(d2, d1 + (d2 - w2) * 2)));
return 0;
}
Compilation message (stderr)
safest.c: In function 'main':
safest.c:38:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | scanf("%d%d%d%d", &n, &m, &s, &t), s--, t--;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
safest.c:40:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | scanf("%d%d%d", &i, &j, &w), i--, j--;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |