이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#define file(data) freopen(data".in", "r", stdin); freopen(data".out", "w", stdout);
#define pb push_back
#define all(data) data.begin(), data.end()
#define endl '\n'
#define ll long long
//#define int long long
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
int n, m, q, k, s[N], t[N], d[N], dang[N], used[N];
vector < pair < int, int > > g[N];
void djk() {
for(int i = 1; i <= n; i++) d[i] = mod;
set < pair < int, int > > st;
for(int i = 1; i <= k; i++) {
d[dang[i]] = 0;
st.insert({0, dang[i]});
}
while(st.size()) {
int now = (*st.begin()).second;
st.erase(*st.begin());
for(int i = 0; i < g[now].size(); i++) {
int to = g[now][i].first, len = g[now][i].second;
if(d[to] > d[now] + len) {
st.erase({d[to], to});
d[to] = d[now] + len;
st.insert({d[to], to});
}
}
}
}
int use;
int slow(int v, int fn) {
set < pair < int, int > > st;
st.insert({d[v], v});
int res = d[v];
while(st.size()) {
int now = (*st.rbegin()).second;
used[now] = use;
res = min(res, d[now]);
if(now == fn) return res;
st.erase(*st.rbegin());
for(int i = 0; i < g[now].size(); i++) {
int to = g[now][i].first;
if(used[to] < use) {
st.insert({d[to], to});
}
}
}
}
main() {
//file("snowcow");
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
set < int > st[n + 1];
for(int i = 1; i <= m; i++) {
int a, b, len; cin >> a >> b >> len;
g[a].pb({b, len});
g[b].pb({a, len});
if(a > b) swap(a, b);
st[a].insert(b);
}
cin >> k;
for(int i = 1; i <= k; i++) {
cin >> dang[i];
}
djk();
cin >> q;
for(int i = 1; i <= q; i++) {
cin >> s[i] >> t[i];
if(s[i] > t[i]) swap(s[i], t[i]);
}
for(int i = 1; i <= q; i++) {
if(st[s[i]].count(t[i])) {
cout << min(d[s[i]], d[t[i]]) << endl;
continue;
}
use = i;
cout << slow(s[i], t[i]) << endl;
}
}
컴파일 시 표준 에러 (stderr) 메시지
plan.cpp: In function 'void djk()':
plan.cpp:32:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int i = 0; i < g[now].size(); i++) {
| ~~^~~~~~~~~~~~~~~
plan.cpp: In function 'int slow(int, int)':
plan.cpp:54:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int i = 0; i < g[now].size(); i++) {
| ~~^~~~~~~~~~~~~~~
plan.cpp: At global scope:
plan.cpp:63:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
63 | main() {
| ^~~~
plan.cpp: In function 'int slow(int, int)':
plan.cpp:45:31: warning: control reaches end of non-void function [-Wreturn-type]
45 | set < pair < int, int > > st;
| ^~
# | 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... |