이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#define fi first
#define se second
#define new new228
#define pb push_back
#define rank rank228
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#pragma warning(disable : 4996)
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // st.oreder_of_key();
const int N = 100100;
const int MAXN = 4 * N;
const int INF = 998244353;
const int MOD = 998244353;
int TN = 1;
int n, m, k, q;
int a[N], d[N], f[20][20];
set<pair<int, int>> st;
vector<pair<int, int>> verr[N];
void solve_1_2() {
for (int i = 1; i <= n; i++) {
d[i] = INF;
}
set<pair<int, int>> st;
for (int i = 1; i <= k; i++) {
d[a[i]] = 0;
st.insert({d[a[i]], a[i]});
}
while (!st.empty()) {
int x = st.begin()->se; st.erase(st.begin());
for (auto i: verr[x]) {
int to = i.fi, len = i.se;
if (d[x] + len < d[to]) {
st.erase({d[to], to});
d[to] = d[x] + len;
st.insert({d[to], to});
}
}
}
while (q--) {
int x, y; scanf("%d %d", &x, &y);
printf("%d\n", min(d[x], d[y]));
}
return;
}
void solve_3() {
//printf("I'm here :)\n");
for (int i = 1; i <= n; i++) {
d[i] = INF;
}
set<pair<int, int>> st;
for (int i = 1; i <= k; i++) {
d[a[i]] = 0;
st.insert({d[a[i]], a[i]});
}
while (!st.empty()) {
int x = st.begin()->se; st.erase(st.begin());
for (auto i: verr[x]) {
int to = i.fi, len = i.se;
if (d[x] + len < d[to]) {
st.erase({d[to], to});
d[to] = d[x] + len;
st.insert({d[to], to});
}
}
}
/*for (int i = 1; i <= n; i++) {
printf("%d ", d[i]);
}
puts("");
*/for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
f[i][j] = -1;
}
}
for (int from = 1; from <= n; from++) {
for (auto to: verr[from]) {
f[from][to.fi] = min(d[from], d[to.fi]);
}
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
//f[i][j] = max(min(d[i], d[j]), min(d[i], min(d[j], d[k])));
f[i][j] = max(f[i][j], min(f[i][k], f[k][j]));
}
}
}
while (q--) {
int x, y;
scanf("%d %d", &x, &y);
printf("%d\n", f[x][y]);
}
}
void solve_4() {
exit(false);
}
signed main() {
// ios_base::sync_with_stdio(0);
// cin.tie(nullptr); cout.tie(nullptr);
// in; out; // cin >> TN;
// while (TN--) { solve(); }
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++) {
int x, y, cost;
scanf("%d %d %d", &x, &y, &cost);
verr[x].pb({y, cost}); verr[y].pb({x, cost});
}
scanf("%d", &k);
for (int i = 1; i <= k; i++) {
scanf("%d", &a[i]);
}
scanf("%d", &q);
/*if (q == 1) {
solve_4(); return 0;
}*/
if (n <= 15 && m <= 200 && q <= 200) {
solve_3(); return 0;
}
if (n <= 100000 && m <= 100000 && q <= 100000) {
solve_1_2(); return 0;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
plan.cpp:22:0: warning: ignoring #pragma warning [-Wunknown-pragmas]
#pragma warning(disable : 4996)
plan.cpp: In function 'void solve_1_2()':
plan.cpp:59:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int x, y; scanf("%d %d", &x, &y);
~~~~~^~~~~~~~~~~~~~~~~
plan.cpp: In function 'void solve_3()':
plan.cpp:110:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &x, &y);
~~~~~^~~~~~~~~~~~~~~~~
plan.cpp: In function 'int main()':
plan.cpp:124:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
plan.cpp:127:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &x, &y, &cost);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
plan.cpp:130:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &k);
~~~~~^~~~~~~~~~
plan.cpp:132:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
~~~~~^~~~~~~~~~~~~
plan.cpp:134:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &q);
~~~~~^~~~~~~~~~
# | 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... |