이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using ld = long double;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll LINF = 2e18;
const double EPS = 1e-9;
#define EMT ios::sync_with_stdio(0); cin.tie(0);
const int N = 1e5 + 25;
int dis[N];
vector<int> npp;
vector<pair<int, int>> edge[N];
void solve() {
memset(dis, 0x3f, sizeof dis);
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
for(int a : npp)
dis[a] = 0, pq.push({dis[a], a});
while(!pq.empty()) {
auto [c, u] = pq.top();
pq.pop();
if(c > dis[u])
continue;
for(const auto &[v, d] : edge[u]) {
if(dis[v] > c + d) {
dis[v] = c + d;
pq.push({dis[v], v});
}
}
}
}
void solve2(int n) { // direct road
int q;
cin >> q;
while(q--) {
int s, t;
cin >> s >> t;
cout << min(dis[s], dis[t]) << '\n';
}
}
void solve1(int n) { // n <= 15
solve2(n);
return;
int q;
cin >> q;
while(q--) {
int s, t;
int res = INF;
for(int i = 0; i < (1 << n); i++) {
}
}
}
signed main() { EMT
int n, m;
cin >> n >> m;
for(int i = 0; i < m; i++) {
int u, v, w;
cin >> u >> v >> w;
edge[u].push_back({v, w});
edge[v].push_back({u, w});
}
int k;
cin >> k;
npp.resize(k);
for(int &a : npp)
cin >> a;
solve();
if(n <= 15) {
solve1(n);
}
else
solve2(n);
}
/*
9 12
1 9 4
1 2 5
2 3 7
2 4 3
4 3 6
3 6 4
8 7 10
6 7 5
5 8 1
9 5 7
5 4 12
6 8 2
2
4 7
5
1 6
5 3
4 8
5 8
1 5
*/
컴파일 시 표준 에러 (stderr) 메시지
plan.cpp: In function 'void solve1(int)':
plan.cpp:53:7: warning: unused variable 's' [-Wunused-variable]
53 | int s, t;
| ^
plan.cpp:53:10: warning: unused variable 't' [-Wunused-variable]
53 | int s, t;
| ^
plan.cpp:54:7: warning: unused variable 'res' [-Wunused-variable]
54 | int res = INF;
| ^~~
# | 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... |