#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
double sub_2_5(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr){
struct ii{
int id;
double w;
};
struct cmp{
bool operator () (ii A, ii B){
return A.w > B.w;
}
};
priority_queue<ii, vector<ii>, cmp> pq;
vector<double> dp(N, (double)(1e15));
vector<vector<pair<int,int>>> G(N);
for(int i=0;i<M;i++){
G[x[i]].push_back({y[i], c[i]});
G[y[i]].push_back({x[i], c[i]});
}
dp[0] = 0;
pq.push({0,dp[0]});
while(pq.size()){
ii u = pq.top();
pq.pop();
if(dp[u.id] < u.w) continue;
for(pair<int,int> v: G[u.id]){
if(dp[u.id] + v.second < dp[v.first]){
dp[v.first] = dp[u.id] + v.second;
pq.push({v.first, dp[v.first]});
}
}
}
if(dp[H] == (double)(1e15)) dp[H] = -1;
return dp[H];
}
double sub_3_6(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr){
struct ii{
int id;
double w;
};
struct cmp{
bool operator () (ii A, ii B){
return A.w > B.w;
}
};
priority_queue<ii, vector<ii>, cmp> pq;
vector<double> dp(N, (double)(1e15));
vector<vector<pair<int,int>>> G(N);
for(int i=0;i<M;i++){
G[x[i]].push_back({y[i], c[i]});
G[y[i]].push_back({x[i], c[i]});
}
dp[0] = 0;
pq.push({0,dp[0]});
vector<bool> vis(N,false);
queue<int> Q;
Q.push(0);
vis[0] = true;
while(Q.size()){
int u = Q.front();
Q.pop();
for(pair<int,int> v: G[u]){
if(vis[v.first] == true || v.first == H) continue;
vis[v.first] = true;
Q.push(v.first);
}
}
for(int i=1;i<N;i++){
if(arr[i] == 0 && vis[i] == true){
dp[i] = 0;
pq.push({i,dp[i]});
}
}
while(pq.size()){
ii u = pq.top();
pq.pop();
if(dp[u.id] < u.w) continue;
for(pair<int,int> v: G[u.id]){
if(dp[u.id] + v.second < dp[v.first]){
dp[v.first] = dp[u.id] + v.second;
pq.push({v.first, dp[v.first]});
}
}
}
if(dp[H] == (double)(1e15)) dp[H] = -1;
return dp[H];
}
double sub_1_4_7(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr){
struct ii{
int id;
int div2;
double w;
};
struct cmp{
bool operator () (ii A, ii B){
return A.w > B.w;
}
};
priority_queue<ii, vector<ii>, cmp> pq;
vector<vector<double>> dp(N, vector<double> (K+2, (double)(1e15)));
vector<vector<pair<int,int>>> G(N);
for(int i=0;i<M;i++){
G[x[i]].push_back({y[i], c[i]});
G[y[i]].push_back({x[i], c[i]});
}
dp[0][0] = 0;
pq.push({0,0,dp[0][0]});
vector<bool> vis(N,false);
queue<int> Q;
Q.push(0);
vis[0] = true;
while(Q.size()){
int u = Q.front();
Q.pop();
for(pair<int,int> v: G[u]){
if(vis[v.first] == true || v.first == H) continue;
vis[v.first] = true;
Q.push(v.first);
}
}
for(int i=1;i<N;i++){
if(arr[i] == 0 && vis[i] == true){
dp[i][0] = 0;
pq.push({i,0,dp[i][0]});
}
}
while(pq.size()){
ii u = pq.top();
pq.pop();
if(dp[u.id][u.div2] < u.w) continue;
if(u.id == H) continue;
for(pair<int,int> v: G[u.id]){
if(dp[u.id][u.div2] + v.second < dp[v.first][u.div2]){
dp[v.first][u.div2] = dp[u.id][u.div2] + v.second;
pq.push({v.first, u.div2, dp[v.first][u.div2]});
}
double tmp = (dp[u.id][u.div2] + v.second) / 2.0;
if(u.div2 + 1 <= K && arr[v.first] == 2){
if(tmp < dp[v.first][u.div2+1]){
dp[v.first][u.div2+1] = tmp;
pq.push({v.first, u.div2+1, dp[v.first][u.div2+1]});
}
}
}
}
double ans = (double)(1e15);
for(int i=0;i<=K;i++) ans = min(ans, dp[H][i]);
if(ans == (double)(1e15)) ans = -1;
return ans;
}
double sub_8(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr){
struct ii{
int id;
int div2;
double w;
};
struct cmp{
bool operator () (ii A, ii B){
return A.w > B.w;
}
};
priority_queue<ii, vector<ii>, cmp> pq;
vector<vector<double>> dp(N, vector<double> (K+2, (double)(1e15)));
vector<vector<pair<int,int>>> G(N);
for(int i=0;i<M;i++){
G[x[i]].push_back({y[i], c[i]});
G[y[i]].push_back({x[i], c[i]});
}
dp[0][0] = 0;
pq.push({0,0,dp[0][0]});
vector<bool> vis(N,false);
queue<int> Q;
Q.push(0);
vis[0] = true;
while(Q.size()){
int u = Q.front();
Q.pop();
for(pair<int,int> v: G[u]){
if(vis[v.first] == true || v.first == H) continue;
vis[v.first] = true;
Q.push(v.first);
}
}
for(int i=1;i<N;i++){
if(arr[i] == 0 && vis[i] == true){
dp[i][0] = 0;
pq.push({i,0,dp[i][0]});
}
}
while(pq.size()){
ii u = pq.top();
pq.pop();
if(dp[u.id][u.div2] < u.w) continue;
if(u.id == H) continue;
for(pair<int,int> v: G[u.id]){
if(dp[u.id][u.div2] + v.second < dp[v.first][u.div2]){
dp[v.first][u.div2] = dp[u.id][u.div2] + v.second;
pq.push({v.first, u.div2, dp[v.first][u.div2]});
}
double tmp = (dp[u.id][u.div2] + v.second) / 2.0;
if(u.div2 + 1 <= K && arr[v.first] == 2){
if(tmp < dp[v.first][u.div2+1]){
dp[v.first][u.div2+1] = tmp;
pq.push({v.first, u.div2+1, dp[v.first][u.div2+1]});
}
}
}
}
double ans = (double)(1e15);
for(int i=0;i<=K;i++) ans = min(ans, dp[H][i]);
if(ans == (double)(1e15)) ans = -1;
return ans;
}
double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr){
int check_sub_2_5 = 0;
for(int i=0;i<N;i++) check_sub_2_5 += (arr[i] == 1);
if(check_sub_2_5 == N) return sub_2_5(N,M,K,H,x,y,c,arr);
int check_sub_3_6 = 0;
for(int i=0;i<N;i++) check_sub_3_6 += (arr[i] != 2);
if(check_sub_3_6 == N) return sub_3_6(N,M,K,H,x,y,c,arr);
if(K <= 30) return sub_1_4_7(N,M,K,H,x,y,c,arr);
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
468 KB |
Correct. |
2 |
Correct |
22 ms |
368 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
444 KB |
Correct. |
2 |
Correct |
26 ms |
468 KB |
Correct. |
3 |
Correct |
23 ms |
468 KB |
Correct. |
4 |
Correct |
24 ms |
472 KB |
Correct. |
5 |
Correct |
24 ms |
500 KB |
Correct. |
6 |
Correct |
20 ms |
1476 KB |
Correct. |
7 |
Correct |
27 ms |
1432 KB |
Correct. |
8 |
Correct |
12 ms |
2656 KB |
Correct. |
9 |
Correct |
24 ms |
380 KB |
Correct. |
10 |
Correct |
25 ms |
468 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
460 KB |
Correct. |
2 |
Correct |
26 ms |
460 KB |
Correct. |
3 |
Correct |
26 ms |
512 KB |
Correct. |
4 |
Correct |
28 ms |
384 KB |
Correct. |
5 |
Correct |
26 ms |
388 KB |
Correct. |
6 |
Correct |
5 ms |
1364 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
269 ms |
27312 KB |
Correct. |
2 |
Correct |
270 ms |
1084 KB |
Correct. |
3 |
Correct |
235 ms |
1160 KB |
Correct. |
4 |
Correct |
251 ms |
1152 KB |
Correct. |
5 |
Correct |
204 ms |
484 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
504 KB |
Correct. |
2 |
Correct |
24 ms |
468 KB |
Correct. |
3 |
Correct |
24 ms |
484 KB |
Correct. |
4 |
Correct |
26 ms |
1492 KB |
Correct. |
5 |
Correct |
22 ms |
384 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
468 KB |
Correct. |
2 |
Correct |
22 ms |
464 KB |
Correct. |
3 |
Correct |
42 ms |
8952 KB |
Correct. |
4 |
Correct |
25 ms |
1200 KB |
Correct. |
5 |
Correct |
25 ms |
384 KB |
Correct. |
6 |
Correct |
25 ms |
480 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
312 ms |
1640 KB |
Correct. |
2 |
Correct |
43 ms |
2352 KB |
Correct. |
3 |
Correct |
810 ms |
29684 KB |
Correct. |
4 |
Correct |
560 ms |
7968 KB |
Correct. |
5 |
Correct |
1690 ms |
49956 KB |
Correct. |
6 |
Correct |
735 ms |
41300 KB |
Correct. |
7 |
Correct |
554 ms |
8216 KB |
Correct. |
8 |
Correct |
531 ms |
1796 KB |
Correct. |
9 |
Correct |
264 ms |
2112 KB |
Correct. |
10 |
Correct |
256 ms |
1532 KB |
Correct. |
11 |
Correct |
507 ms |
1024 KB |
Correct. |
12 |
Correct |
275 ms |
1604 KB |
Correct. |
13 |
Correct |
289 ms |
1708 KB |
Correct. |
14 |
Correct |
503 ms |
10924 KB |
Correct. |
15 |
Correct |
507 ms |
3372 KB |
Correct. |
16 |
Correct |
266 ms |
1584 KB |
Correct. |
17 |
Correct |
318 ms |
1520 KB |
Correct. |
18 |
Correct |
325 ms |
1500 KB |
Correct. |
19 |
Correct |
753 ms |
1640 KB |
Correct. |
20 |
Correct |
20 ms |
724 KB |
Correct. |
21 |
Correct |
20 ms |
1060 KB |
Correct. |
22 |
Correct |
37 ms |
3228 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
340 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |