이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#ifdef MINA
#include "grader.cpp"
#endif
using namespace std;
#define ll long long
const int N = 2005;
int n, m;
array<int, 3> e[N];
vector<int> adj[N];
void init(int _n, int _m, vector<int> u, vector<int> v, vector<int> w) {
n = _n, m = _m;
for (int i = 0; i < m; i++) {
e[i] = {u[i], v[i], w[i]};
}
sort(e, e + m, [&] (array<int, 3> x, array<int, 3> y) {return x[2] < y[2];});
}
int dist[N][N], ok[N], t[N], low[N], cur, vis[N], bad;
int dfs(int i, int p, int x, int y) {
vis[i] = 1;
t[i] = low[i] = cur++;
int cnt = 0;
for (auto nxt : adj[i]) {
if (nxt == p) continue;
if (vis[nxt]) {
low[i] = min(low[i], t[nxt]);
} else {
int val = dfs(nxt, i, x, y);
low[i] = min(low[i], low[nxt]);
if (low[nxt] > t[i] && val == 1) {
bad = 1;
}
cnt += val;
}
}
cnt += i == x || i == y;
return cnt;
}
int getMinimumFuelCapacity(int x, int y) {
int l = 0, r = m - 1;
while (l <= r) {
int md = ((l + r) >> 1);
for (int i = 0; i < n; i++) {
adj[i].clear();
for (int j = 0; j < n; j++) {
dist[i][j] = 1e9;
}
ok[i] = 0;
vis[i] = 0;
}
bad = 0;
for (int i = 0; i <= md; i++) {
adj[e[i][0]].push_back(e[i][1]);
adj[e[i][1]].push_back(e[i][0]);
}
queue<array<int, 2>> q;
q.push({x, y});
dist[x][y] = 0;
while (q.size()) {
int i = q.front()[0];
int j = q.front()[1];
q.pop();
for (auto nxt : adj[i]) {
if (nxt != j && dist[nxt][j] != 0) {
dist[nxt][j] = 0;
q.push({nxt, j});
}
}
for (auto nxt : adj[j]) {
if (nxt != i && dist[i][nxt] != 0) {
dist[i][nxt] = 0;
q.push({i, nxt});
}
}
}
if (dist[y][x] == 0) {
r = md - 1;
} else {
l = md + 1;
}
}
if (l == m) {
return -1;
}
return e[l][2];
}
# | 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... |