이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "swap.h"
#include <vector>
#include <algorithm>
using namespace std;
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define oo 1000000001
struct edge{
int u, v;
int cost;
bool operator< (edge e) const{
return cost < e.cost;
}
};
vector<int> pr;
vector<edge> ed;
vector<int> deg;
vector<vector<int>> cmp;
vector<vector<pii>> arr;
vector<int> when;
void Union(edge e){
deg[e.u]++; deg[e.v]++;
int x = pr[e.u];
int y = pr[e.v];
if (x == y){
when[x] = min(when[x], e.cost);
return;
}
if (cmp[x].size() < cmp[y].size()) swap(x, y);
for (auto node : cmp[y]){
cmp[x].pb(node);
pr[node] = x;
arr[node].pb({x, e.cost});
}
cmp[y].clear();
if (when[y] != oo) when[x] = min(when[x], e.cost);
if (deg[e.u] >= 3 || deg[e.v] >= 3) when[x] = min(when[x], e.cost);
}
void init(int n, int m, vector<int> u, vector<int> v, vector<int> w) {
pr.resize(n);
ed.resize(m);
deg.resize(n);
cmp.resize(n);
arr.resize(n);
when.resize(n);
for (int i = 0; i < m; ++i) {
ed[i].u = u[i];
ed[i].v = v[i];
ed[i].cost = w[i];
}
for (int i = 0; i < n; ++i) {
pr[i] = i;
cmp[i].pb(i);
deg[i] = 0;
arr[i].pb({i, 0});
when[i] = oo;
}
sort(ed.begin(), ed.end());
for (int i = 0; i < m; ++i) {
Union(ed[i]);
}
}
int getMinimumFuelCapacity(int x, int y) {
int ans = 0;
if (when[pr[x]] == oo) return -1;
int cmpx = x, cmpy = y;
int a = 0, b = 0;
while (cmpx != cmpy || when[cmpx] == oo){
if (a == arr[x].size()){
cmpy = arr[y][b].f;
ans = max(ans, arr[y][b++].s);
} else if (b == arr[y].size()){
cmpx = arr[x][a].f;
ans = max(ans, arr[x][a++].s);
} else if (arr[x][a].s < arr[y][b].s){
cmpx = arr[x][a].f;
ans = max(ans, arr[x][a++].s);
} else{
cmpy = arr[y][b].f;
ans = max(ans, arr[y][b++].s);
}
}
ans = max(ans, when[cmpx]);
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:92:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | if (a == arr[x].size()){
| ~~^~~~~~~~~~~~~~~~
swap.cpp:95:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | } else if (b == arr[y].size()){
| ~~^~~~~~~~~~~~~~~~
# | 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... |