이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fst first
#define snd second
#define pb push_back
#define forn(i,a,b) for(int i = a; i < b; i++)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define dbg(v) cout<<"Line("<<__LINE__<<"): "<<#v<<" = "<<v<<'\n';
#define pi pair<int,int>
#define pll pair<ll,ll>
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_multiset;
ll n,m,k,h;
vector<vector<pll>> adj;
vector<ll> type;
vector<bool> inComp;
void dfs(ll nd){
if(inComp[nd]) return;
inComp[nd]=1;
if(nd==h) return;
for(auto i:adj[nd]) dfs(i.fst);
}
double dijkstra(){
double dist[n+1][35];
//mset(dist,-1);// -> No funcaaa AHHHHH
forn(i,0,n+1)forn(j,0,35) dist[i][j]=-1; // -> Este si funciona
priority_queue<pair<double,pll>> pq;
dist[0][0]=0;
forn(i,0,n) if(type[i]==0) dist[i][0]=0,pq.push({0,{i,0}});
pq.push({0,{0,0}});
while(!pq.empty()){
double cost = pq.top().fst*-1;
ll nd = pq.top().snd.fst;
ll p2 = pq.top().snd.snd;
pq.pop();
if(dist[nd][p2]<cost&&dist[nd][p2]!=-1) break;
if(nd==h) return cost;
for(auto i:adj[nd]){
if(type[i.fst]==0) continue;
if(cost+i.snd<dist[i.fst][p2]||dist[i.fst][p2]==-1){
dist[i.fst][p2]=cost+i.snd;
pq.push({dist[i.fst][p2]*-1,{i.fst,p2}});
//cout<<dist[i.fst][p2]<<'\n';
}
if(type[i.fst]==2){
if(p2+1<35){
if((cost+i.snd)/2<dist[i.fst][p2+1]||dist[i.fst][p2+1]==-1){
dist[i.fst][p2+1]=(cost+i.snd)/2;
//cout<<dist[i.fst][p2+1]<<'\n';
pq.push({dist[i.fst][p2+1]*-1,{i.fst,p2+1}});
}
}
}
}
}
double res = -1;
forn(j,0,35){
if(dist[h][j]!=-1&&(dist[h][j]<res||res==-1)) res = dist[h][j];
}
//cout<<res<<'\n';
return res;
}
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){
n=N;m=M;k=K;h=H;
adj.clear();
adj.resize(n);
type.clear();
type.resize(n);
inComp.clear();
inComp.resize(n,0);
forn(i,0,SZ(x)) adj[x[i]].pb({y[i],c[i]}),adj[y[i]].pb({x[i],c[i]});
forn(i,0,n) type[i]=arr[i];
dfs(0);
return dijkstra();
}
# | 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... |