이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma optimize("Bismillahirrahmanirrahim")
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█■█
//█─█─█▄─█▄─█─█─█─█
//Allahuekber
//ahmet23 orz...
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//YavuzSultanSelimHan
//AbdulhamidHan
#define author tolbi
#include <bits/stdc++.h>
#ifdef LOCAL
#include "23.h"
#endif
#define int long long
#define endl '\n'
#define vint(x) vector<int> x
#define deci(x) int x;cin>>x;
#define decstr(x) string x;cin>>x;
#define cinarr(x) for (auto &it : x) cin>>it;
#define coutarr(x) for (auto &it : x) cout<<it<<" ";cout<<endl;
#define sortarr(x) sort(x.begin(),x.end())
#define sortrarr(x) sort(x.rbegin(),x.rend())
#define det(x) cout<<"NO\0YES"+x*3<<endl;
#define INF LONG_LONG_MAX
#define rev(x) reverse(x.begin(),x.end());
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define tol(bi) (1LL<<((int)(bi)))
const int MOD = 1e9+7;
using namespace std;
mt19937 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count());
int32_t main(){
ios;
int t=1;
int tno = 0;
if (!t) cin>>t;
while (t-(tno++)){
deci(n);deci(m);
vector<vector<pair<int,int>>> arr(n);
for (int i = 0; i < m; i++){
deci(u);deci(v);deci(w);
arr[u-1].push_back({v-1,w});
arr[v-1].push_back({u-1,w});
}
deci(k);
vector<int> zar(n,MOD);
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
for (int i = 0; i < k; i++){
deci(x);
pq.push({0,x-1});
}
while (pq.size()){
int nod = pq.top().second;
int w = pq.top().first;
pq.pop();
if (zar[nod]<=w) continue;
zar[nod]=w;
for (int i = 0; i < arr[nod].size(); i++){
if (zar[arr[nod][i].first]<=w+arr[nod][i].second) continue;
pq.push({w+arr[nod][i].second,arr[nod][i].first});
}
}
deci(q);
while (q--){
deci(u);deci(v);
if (n>1000 && q>1){
cout<<min(zar[u-1],zar[v-1])<<endl;
continue;
}
int l = 0, r = MOD;
queue<int> ppq;
while (l<r){
int mid = l+(r-l+1)/2;
if (zar[u-1]<mid) {
r=mid-1;
continue;
}
ppq.push(u-1);
vector<bool> var(n);
while (ppq.size()){
int node = ppq.front();
ppq.pop();
if (var[node]) continue;
var[node]=true;
for (int i = 0; i < arr[node].size(); i++){
if (zar[arr[node][i].first]<mid) continue;
if (var[arr[node][i].first]) continue;
if (arr[node][i].first==v-1){
var[v-1]=true;
break;
}
ppq.push(arr[node][i].first);
}
if (var[v-1]){
while (ppq.size()) ppq.pop();
break;
}
}
if (var[v-1]){
l=mid;
}
else r = mid-1;
}
cout<<l<<endl;
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
plan.cpp:1: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
1 | #pragma optimize("Bismillahirrahmanirrahim")
|
plan.cpp: In function 'int32_t main()':
plan.cpp:59:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (int i = 0; i < arr[nod].size(); i++){
| ~~^~~~~~~~~~~~~~~~~
plan.cpp:86:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for (int i = 0; i < arr[node].size(); i++){
| ~~^~~~~~~~~~~~~~~~~~
# | 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... |