# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
268253 | MKopchev | Commuter Pass (JOI18_commuter_pass) | C++14 | 719 ms | 24412 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int nmax=1e5+42;
int n,m;
vector< pair<int/*to*/,int/*cost*/> > adj[nmax];
int s,t;
int u,v;
long long dist[4][nmax];//from s, from t, from u, from v
priority_queue< pair<long long/*dist*/,int/*node*/> > pq;
void dij(int node,int id)
{
pq.push({0,node});
while(pq.size())
{
pair<long long/*dist*/,int/*node*/> tp=pq.top();
pq.pop();
tp.first=-tp.first;
//cout<<tp.first<<" "<<tp.second<<endl;
if(dist[id][tp.second]!=-1)continue;
dist[id][tp.second]=tp.first;
for(auto k:adj[tp.second])
{
pq.push({-(tp.first+k.second),k.first});
//cout<<"edge "<<k.first<<" "<<k.second<<endl;
}
}
/*
cout<<id<<endl;
for(int i=1;i<=n;i++)cout<<dist[id][i]<<" ";cout<<endl;
*/
}
long long mini[nmax];
bool been[nmax];
vector<int> dag_edges[nmax];
int OTHER;
long long find_mini(int node)
{
if(been[node])return mini[node];
mini[node]=dist[OTHER][node];
for(auto k:dag_edges[node])
{
mini[node]=min(mini[node],find_mini(k));
}
been[node]=1;
return mini[node];
}
long long solve(int original,int other)
{
//cout<<original<<" "<<other<<" : "<<endl;
OTHER=other;
memset(been,0,sizeof(been));
for(int i=1;i<=n;i++)mini[i]=1e18;
for(int i=1;i<=n;i++)dag_edges[i]={};
for(int i=1;i<=n;i++)
for(auto k:adj[i])
if(dist[0][i]+k.second+dist[1][k.first]==dist[0][t]&&dist[0][i]<dist[0][k.first])
{
//cout<<i<<" -> "<<k.first<<endl;
dag_edges[i].push_back(k.first);
}
/*
cout<<"find mini"<<endl;
for(int i=1;i<=n;i++)cout<<i<<" -> "<<find_mini(i)<<endl;
*/
long long ret=1e18;
for(int i=1;i<=n;i++)
{
long long cur=dist[original][i];
cur=cur+find_mini(i);
//cout<<i<<" -> "<<cur<<" "<<dist[original][i]<<" "<<find_mini(i)<<endl;
ret=min(ret,cur);
}
//cout<<"ret= "<<ret<<endl;
return ret;
}
int main()
{
memset(dist,-1,sizeof(dist));
scanf("%i%i",&n,&m);
scanf("%i%i",&s,&t);
scanf("%i%i",&u,&v);
for(int i=1;i<=m;i++)
{
int a,b,c;
scanf("%i%i%i",&a,&b,&c);
adj[a].push_back({b,c});
adj[b].push_back({a,c});
}
dij(s,0);
dij(t,1);
dij(u,2);
dij(v,3);
long long outp=dist[3][u];
outp=min(outp,solve(3,2));
outp=min(outp,solve(2,3));
printf("%lld\n",outp);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |