이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 1e5 + 9;
const ll Log2 = 20;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;
vector<LL> g[N];
ll n,m,x,y,w,k,d[N],pos[N];
priority_queue<LL,vector<LL>,greater<LL>> pq;
void Dij(){
while(!pq.empty()){
LL t = pq.top(); pq.pop();
ll u = t.sc,val = t.fs;
for (auto i : g[u]){
ll v = i.fs,L = i.sc;
if (d[v] > val + L){
d[v] = val + L; pq.push({d[v],v});
}
}
}
}
bool lf(ll x,ll y){
return d[x] > d[y];
}
ll lab[N];
ll Find(ll u){
if (lab[u] < 0) return u;
return lab[u] = Find(lab[u]);
}
void Union(ll p,ll q){
ll r = Find(p),s = Find(q);
if (r == s) return;
if (lab[r] > lab[s]) swap(r,s);
lab[r] += lab[s]; lab[s] = r;
}
LL q[N];
ll l[N],h[N],was[N],Q;
vector<ll> v[N];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define task "test"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
}
cin>>n>>m;
for (ll i = 1;i <= m;i++){
cin>>x>>y>>w;
g[x].push_back({y,w}); g[y].push_back({x,w});
}
for (ll i = 1;i <= n;i++){
d[i] = inf; pos[i] = i;
}
cin>>k;
for (ll i = 1;i <= k;i++) cin>>x,d[x] = 0,pq.push({0,x});
Dij(); sort(pos + 1,pos + n + 1,lf);
cin>>Q;
for (ll i = 1;i <= Q;i++) cin>>q[i].fs>>q[i].sc,l[i] = 1,h[i] = n;
for (ll i = 1;i <= 45;i++){
memset(lab,-1,sizeof(lab)); memset(was,0,sizeof(was));
for (ll j = 1;j <= n;j++) v[j].clear();
for (ll j = 1;j <= Q;j++){
if (l[j] > h[j]) continue;
ll mid = (l[j] + h[j]) / 2;
v[mid].push_back(j);
}
for (ll j = 1;j <= n;j++){
ll now = pos[j]; was[now] = 1;
for (auto k : g[now]) if (was[k.fs]) Union(now,k.fs);
for (auto k : v[j]){
if (Find(q[k].fs) == Find(q[k].sc)) h[k] = j - 1;
else l[k] = j + 1;
}
}
}
for (ll i = 1;i <= Q;i++){
ll now = pos[l[i]];
cout<<d[now]<<"\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
plan.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
1 | #pragma GCC optimization "O2"
|
plan.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization "unroll-loop"
|
plan.cpp: In function 'int main()':
plan.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |