제출 #951245

#제출 시각아이디문제언어결과실행 시간메모리
951245NourWaelRelay Marathon (NOI20_relaymarathon)C++17
0 / 100
2 ms2396 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...