이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
int const mxN = 1e3+5;
vector<pair<int,int>> adj[mxN];
vector<int> spe;
bool is[mxN], vis[mxN];
int dist[mxN][mxN], cur[mxN];
int n;
void solve ( int i , int e1, int e2, bool f) {
memset(vis,0,sizeof vis);
for(int j=1; j<=n; j++) cur[j] = 1e18;
priority_queue<pair<int,int>> q;
q.push({0,i});
while(q.size()) {
int node = q.top().second, d = -(q.top().first);
q.pop();
if(vis[node]) continue;
vis[node] = 1;
for(auto it:adj[node]) {
if(cur[it.first]<=d+it.second) continue;
cur[it.first] = d+it.second;
q.push({-(d+it.second), it.first});
}
}
for(int j=1; j<=n; j++) dist[i][j] = cur[j];
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
int m,k; cin>>n>>m>>k;
for(int i=0; i<m; i++) {
int x,y,c; cin>>x>>y>>c;
adj[x].push_back({y,c}), adj[y].push_back({x,c});
}
for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) dist[i][j] = 1e18;
for(int i=0; i<k; i++) {
int x; cin>>x;
is[x] = 1;
spe.push_back(x);
}
for(int i=1; i<=n; i++) solve(i, 0, 0, 0);
int ans = 1e18;
for(int i=1; i<=n; i++) {
if(!is[i]) continue;
for(int j=1; j<=n; j++) {
if(!is[j] || j==i) continue;
for(int h=1; h<=n; h++) {
if(!is[h] || h==i || h==j) continue;
for(int l=1; l<=n; l++) {
if(!is[l] || l==i || l==j || l==h) continue;
if(dist[i][j] + dist[h][l]<ans) { cout<<i<<' '<<j<<' '<<h<<' '<<l<<'\n'; ans = dist[i][j] + dist[h][l];}
}
}
}
}
cout<<ans;
return 0;
}
# | 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... |