이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long
#define mod 1000000007
ofstream fout(".out");
ifstream fin(".in");
vector<pair<int, int>> v[100001];
int d[100001];
bool vis[100001];
int s, t;
int dfs(int x) {
if(x == t)
return d[x];
vis[x] = 1;
int mx = 0;
for(auto i : v[x]) {
if(d[i.first] && !vis[i.first])
mx = max(mx, dfs(i.first));
}
vis[x] = 0;
return min(d[x], mx);
}
void dijkstra(int y) {
set<pair<int, int>> s;
s.insert({0, y});
while(s.size()) {
pair<int, int> p = *s.begin();
s.erase(s.begin());
int x = p.second;
int cost = p.first;
if(d[x] == 0) {
d[y] = cost;
return;
}
for(auto i : v[x])
s.insert({cost + i.second, i.first});
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++)
d[i] = 1e9;
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});
}
int k;
cin >> k;
for(int i = 0; i < k; i++) {
int x;
cin >> x;
d[x] = 0;
}
for(int i = 1; i <= n; i++) {
if(d[i])
dijkstra(i);
}
int q;
cin >> q;
while(q--) {
cin >> s >> t;
cout << min(d[s], d[t]) << "\n";
}
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... |