#include <bits/stdc++.h>
using namespace std;
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pii pair<int, int>
const ll mod = 1e9 + 7;
vector<pii> G[100005];
int x, y, n, m, par[100005], s, e;
void make_set() {
for (int i = 1; i <= n; i++)
par[i] = i;
}
int find_set(int v) {
if (par[v] == v)
return v;
return par[v] = find_set(par[v]);
}
bool union_set(int a, int b) {
a = find_set(a);
b = find_set(b);
if (a != b) {
par[b] = a;
return true;
} return false;
}
void dfs(int v, int par, int cur) {
if (v == e) {
cout << cur;
return;
} for (auto u : G[v])
if (u.ff != par) dfs(u.ff, v, max(cur, u.sc));
}
void solve() {
cin >> n >> m;
make_set();
cin >> s >> e;
vector<pii> edj;
for (int i = 1; i <= m; i++) {
cin >> x >> y;
edj.pb({x, y});
} int val[n + 1];
for (int i = 1; i <= n; i++)
cin >> val[i];
set<pair<int, pii>> st;
for (auto v : edj)
st.insert({abs(val[v.ff] - val[v.sc]), v});
for (auto v : st) {
if (union_set(v.sc.ff, v.sc.sc)) {
G[v.sc.ff].pb({v.sc.sc, v.ff}); G[v.sc.sc].pb({v.sc.ff, v.ff});
}
} dfs(s, -1, -1);
}
int main() {
int t = 1;
// cin >> t;
while (t--) {
solve();
cout << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |