이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <fstream>
#define endl '\n'
#define mod 32768
#define INF 100000000000000
//#define ll long long
//#define cin fin
//#define cout fout
using namespace std;
//ofstream fout("convention.out");
//ifstream fin("convention.in");
const int M = 1e3 + 5;
long long arr[M][M];
vector<pair<int,long long>> v[M];
void d(int s)
{
for(int i = 0; i < M; i++)
{
arr[s][i] = INF;
}
arr[s][s] = 0;
priority_queue<pair<long long,int>, vector<pair<long long, int>>, greater<pair<long long,int>>> pq;
pq.push({arr[s][s],s});
while(!pq.empty())
{
pair<long long,int> tp = pq.top();
pq.pop();
if(arr[s][tp.second] < tp.first)
continue;
for(auto i : v[tp.second])
{
if(arr[s][tp.second]+i.second < arr[s][i.first])
{
arr[s][i.first] = arr[s][tp.second]+i.second;
pq.push({arr[s][i.first],i.second});
}
}
}
}
int main()
{
int n, m, k, q;
cin >> n >> m;
for(int i = 0; i < m; i++)
{
int a, b, c;
cin >> a >> b >> c;
v[a].push_back({b,c});
v[b].push_back({a,c});
}
cin >> k;
int a[k];
for(int i = 0; i < k; i++)
{
cin >> a[i];
d(a[i]);
}
cin >> q;
while(q--)
{
int s, t;
cin >> s >> t;
long long ans = INF;
for(int i = 0; i < k; i++)
{
ans = min(ans,arr[a[i]][s]);
ans = min(ans,arr[a[i]][t]);
}
cout << ans << endl;
}
return 0;
}
# | 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... |