이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optomize ("Ofast")
//#pragma GCC optomize ("unroll-loops")
//#pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define sz size
#define cl clear
#define ins insert
#define ers erase
#define pii pair < int , int >
#define pll pair< long long , long long >
#define all(x) x.begin() , x.end()
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define tostr(x) to_string(x)
#define tonum(s) atoi(s.c_str())
#define seon(x) setprecision(x)
#define bpop(x) __builtin_popcount(x)
#define deb(x) cerr << #x << " = " << x << endl;
#define int ll
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const double PI = 3.14159265;
const ll N = 2e5+5;
const ll mod = 1e9+7;
const ll inf = 1e9;
const ll INF = 1e18;
using namespace std;
ll n , m , q;
ll dp[N];
vector<pll> g[N];
ll road[N];
void bfs(){
set<pll> st;
int k;
cin >> k;
for(int i = 1; i <= n; i++) dp[i] = INF;
for(int i = 1; i <= k; i++) {
int u;
cin >> u;
dp[u] = 0;
st.ins({0 , u});
}
while(st.sz()){
int v = st.begin()->S;
st.ers(st.begin());
for(pll to : g[v]){
if(dp[to.F] > dp[v]+to.S){
st.ers({dp[to.F] , to.F});
dp[to.F] = dp[v]+to.S;
st.ins({dp[to.F] , to.F});
}
}
}
}
void solve(){
cin >> n >> m;
for(int i = 1; i <= m; i++){
int a, b , c;
cin >> a>> b >> c;
g[a].pb({b , c});
g[b].pb({a , c});
}
bfs();
for(int i = 1; i <= n; i++) road[i] = 0;
cin >> q;
while(q--){
int u , b;
cin >> u >> b;
road[u] = dp[u];
set<pll> st;
st.ins({road[u] , u});
while(st.sz() > 0){
int v = st.begin()->S;
st.ers(st.begin());
for(pll x : g[v]){
ll to = x.F , c = x.S;
if(road[to] < min(road[v] , dp[to])){
st.ers({road[to] , to});
road[to] = min(road[v] , dp[to]);
st.ins({road[to] , to});
}
}
}
cout << road[b] <<"\n";
}
}
signed main(){
ios;
solve();
return 0;
}
/*
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
1
5 8
*/
컴파일 시 표준 에러 (stderr) 메시지
plan.cpp: In function 'void solve()':
plan.cpp:87:19: warning: unused variable 'c' [-Wunused-variable]
87 | ll to = x.F , c = x.S;
| ^
# | 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... |