이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
double solve(int32_t N, int32_t M, int32_t K, int32_t H, vector<int32_t> x, vector<int32_t> y, vector<int32_t> c, vector<int32_t> arr) {
if(N==2){
return M ? c[0] : -1;
}
double ans = 3e9;
vector<int32_t > lookup;
if(H==1)lookup = {0,1,2};
else lookup = {0,2,1};
int c1=2e9+1,c2=2e9+1,c3=2e9+1;
for(int i=0;i<M;i++){
x[i] = lookup[x[i]];
y[i] = lookup[y[i]];
if(x[i]>y[i])swap(x[i],y[i]);
if(x[i]==0 and y[i]==1)c1=c[i];
if(x[i]==0 and y[i]==2)c2=c[i];
if(x[i]==1 and y[i]==2)c3=c[i];
}
if(c1<=2e9)ans=min(ans,(double)c1);
if(c2<=2e9 and c3<=2e9){
if(arr[2]==0)ans=min(ans,(double)c3);
else if(arr[2]==2 and K)ans=min(ans,(double)(c2)/(double)(2)+c3);
else ans = min(ans,(double)(c2+c3));
}
return ans>2e9 ? -1 : ans;
}
//int32_t main() {
// int32_t T;
// assert(1 == scanf("%d", &T));
// while (T--){
// int32_t N,M,K,H;
// assert(4 == scanf("%d %d %d\n%d", &N, &M, &K, &H));
// std::vector<int32_t> x(M);
// std::vector<int32_t> y(M);
// std::vector<int32_t> c(M);
// std::vector<int32_t> arr(N);
// for (int32_t i=0;i<N;i++)
// assert(1 == scanf("%d", &arr[i]));
// for (int32_t i=0;i<M;i++)
// assert(3 == scanf("%d %d %d", &x[i], &y[i], &c[i]));
// printf("%.12lf\n", solve(N, M, K, H, x, y, c, arr));
// }
//}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |