이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define ld long double
#define cd complex<ld>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pld pair<ld,ld>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll n, m;
vector<pll> T[100005];
ll save[4];
ll dis[4][10005];
bool chk[100005];
bool in[100005];
ll dp[100005];
ll sum[100005];
vector<ll> adj[100005];
ll ans = LLONG_MAX;
void dijsktra(ll type)
{
for(int i = 1; i<= n; i++) dis[type][i] = LLONG_MAX;
for(int i = 1; i<= n; i++) chk[i] = 0;
priority_queue<pll,vector<pll>, greater<pll>> q;
dis[type][save[type]] = 0;
q.push(mp(0 , save[type]));
while(!q.empty())
{
ll path = q.top().fi, x = q.top().se;
q.pop();
if(chk[x]||dis[type][x]!=path) continue;
//cout << type << " " << path << " " << x << "-\n";
chk[x] = 1;
for(auto u: T[x])
{
ll cur = path+u.se;
if(cur<dis[type][u.fi])
{
dis[type][u.fi] = cur;
q.push(mp(dis[type][u.fi], u.fi));
}
}
}
}
void dfs(ll v)
{
for(auto x: adj[v])
{
dfs(x);
dp[v] = min(dp[v], dp[x]);
}
ans = min(ans, dp[v]+sum[v]);
}
void solve()
{
cin >> n >> m;
cin >> save[2] >> save[3] >> save[0] >> save[1];
for(int i = 0 ;i< m; i++)
{
ll a, b, c;
cin >> a >> b >> c;
T[a].push_back(mp(b,c));
T[b].push_back(mp(a,c));
}
dijsktra(2); dijsktra(3);
}
signed main()
{
//freopen("IN.txt","r",stdin);
//freopen("OUT.txt","w",stdout);
ios_base::sync_with_stdio(NULL) ; cin.tie(nullptr) ; cout.tie(nullptr);
ll t = 1;
//cin >> t;
while(t--)
{
solve();
cout << "\n";
}
}
# | 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... |