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 <bits/stdc++.h>
#include "swap.h"
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 300010, inf = 1e9 + 7;
struct dsu {
vector<int> g, sz, good;
dsu(int n) { g.resize(n), sz.resize(n, 1), good.resize(n); iota(AI(g), 0); }
int F(int i) { return i == g[i] ? i : g[i] = F(g[i]); }
void M(int a, int b) {
a = F(a), b = F(b);
if (a == b) return good[a] = true, void();
if (sz[a] < sz[b]) swap(a, b);
return g[b] = a, sz[a] += sz[b], good[a] |= good[b], void();
}
bool qry(int a, int b) {
if (F(a) != F(b)) return false;
return good[F(a)];
}
};
int n, m;
vector<tuple<int,int,int>> alle;
void init(int N, int M,
std::vector<int> U, std::vector<int> V, std::vector<int> W) {
n = N, m = M;
for (int i = 0;i < M;++i) {
alle.pb(W[i], U[i], V[i]);
}
sort(AI(alle));
}
int getMinimumFuelCapacity(int X, int Y) {
dsu D(n);
for (auto [w, a, b] : alle) {
D.M(a, b);
if (D.qry(X, Y)) return w;
}
return -1;
}
| # | 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... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |