이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//-------------dilanyan------------\\
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
//------------------KarginDefines--------------------\\
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
#define Kargin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Usaco freopen(".in", "r", stdin); freopen(".out", "w", stdout);
//-------------------KarginConstants------------------\\
const ll mod = 1000000007;
const ll inf = 1e9 + 15;
//-------------------KarginCode------------------------\\
const int N = 100005;
int n;
vector<pair<int, int>> g[N];
int dist[N];
void dijikstra(int s) {
pqueue<pair<int, int>> pq;
vector<bool> vis(n + 1, false);
vector<int> d(n + 1, inf);
d[s] = 0;
pq.push({ 0,s });
while (!pq.empty()) {
int u = pq.top().second; pq.pop();
if (vis[u]) continue;
vis[u] = true;
for (auto it : g[u]) {
int v = it.first, w = it.second;
if (d[v] > d[u] + w) {
d[v] = d[u] + w;
pq.push({ -d[v],v });
}
}
}
for (int i = 1;i <= n;i++) dist[i] = min(dist[i], d[i]);
}
void KarginSolve() {
int m;
cin >> n >> m;
for (int i = 0;i < m;i++) {
int u, v, w;
cin >> u >> v >> w;
g[u].pb({ v,w }), g[v].pb({ u,w });
}
int k; cin >> k;
fill(dist + 1, dist + n + 1, inf);
for (int i = 0; i < k;i++) {
int u; cin >> u;
dijikstra(u);
}
int q; cin >> q;
for (int i = 0;i < q;i++) {
int s, t;
cin >> s >> t;
cout << min(dist[s], dist[t]) << '\n';
}
}
int main() {
//Usaco
Kargin;
int test = 1;
//cin >> test;
while (test--) {
KarginSolve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
plan.cpp:1:1: warning: multi-line comment [-Wcomment]
1 | //-------------dilanyan------------\\
| ^
plan.cpp:8:1: warning: multi-line comment [-Wcomment]
8 | //------------------KarginDefines--------------------\\
| ^
plan.cpp:22:1: warning: multi-line comment [-Wcomment]
22 | //-------------------KarginConstants------------------\\
| ^
plan.cpp:27:1: warning: multi-line comment [-Wcomment]
27 | //-------------------KarginCode------------------------\\
| ^
# | 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... |