이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define ll long long
#define ull unsigned long long
#define f first
#define s second
#define PB push_back
#define MP make_pair
#define max(a, b) ((a > b)? a : b)
#define min(a, b) ((a < b)? a : b)
const int N = 1e5 + 5;
const int M = 1e9 + 7;
const int INF = 0x3f3f3f3f;
// Make variable global
vector<vector<pair<int, int>>> adj(N, vector<pair<int, int>>());
vector<int> power;
vector<bool> vis(N, false);
long double ans = 1e15;
void dfs(int cur, int prev, double time){
if(power[cur] == 0 || cur == 0) ans = min(ans, time);
vis[cur] = true;
for(pair<int, int> p : adj[cur]){
if(p.f == prev) continue;
dfs(p.f, cur, time + p.s);
}
}
double solve(int n, int m, int k, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr){
// Make Adjacency List
for(int i = 0; i < m; i++){
adj[x[i]].PB(MP(y[i], c[i]));
adj[y[i]].PB(MP(x[i], c[i]));
}
power = arr;
// Solve Subtask 3
// Connected tree, possible ability is arr{0, 1}
dfs(h, -1, 0);
return (vis[0])? ans : -1;
}
// int main(){
// ios::sync_with_stdio(false);
// cin.tie(NULL);
// // ifstream cin();
// // ofstream cout();
// cout << solve(3, 2, 30, 2, {1, 2}, {2, 0}, {12, 4}, {1, 2, 1}) << endl;
// cout << solve(4, 4, 30, 3, {0, 0, 1, 2}, {1, 2, 3, 3}, {5, 4, 2, 4}, {1, 0, 2, 1}) << endl;
// }
# | 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... |