제출 #1247662

#제출 시각아이디문제언어결과실행 시간메모리
1247662hainam2k9Cities (BOI16_cities)C++20
100 / 100
1327 ms50732 KiB
#include <bits/stdc++.h> #define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0) #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout) #define ll long long #define ull unsigned long long #define i128 __int128 #define db long double #define sz(a) ((int)(a).size()) #define pb emplace_back #define pf emplace_front #define pob pop_back #define pof pop_front #define lb lower_bound #define ub upper_bound #define fi first #define se second #define ins emplace #define mp make_pair using namespace std; const int MOD = 1e9+7, MAXN = 1e5+5; const string NAME = ""; int n,k,m,a[10]; ll dist[10][MAXN],dp[35][MAXN],rs=1e18; vector<pair<int,int>> adj[MAXN]; inline void dijkstra(ll dist[MAXN], int u){ priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq; dist[u]=0, pq.ins(0,u); while(!pq.empty()){ pair<ll,int> top = pq.top(); pq.pop(); if(top.fi>dist[top.se]) continue; for(pair<int,int>& e : adj[top.se]) if(dist[e.fi]>top.fi+e.se) dist[e.fi]=top.fi+e.se, pq.ins(dist[e.fi],e.fi); } } inline void dijkstra2(ll dist[MAXN]){ priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq; for(int i = 1; i<=n; ++i) pq.ins(dist[i],i); while(!pq.empty()){ pair<ll,int> top = pq.top(); pq.pop(); if(top.fi>dist[top.se]) continue; for(pair<int,int>& e : adj[top.se]) if(dist[e.fi]>top.fi+e.se) dist[e.fi]=top.fi+e.se, pq.ins(dist[e.fi],e.fi); } } int main() { tt; if(fopen((NAME + ".INP").c_str(), "r")) fo; cin >> n >> k >> m; for(int i = 0; i<k; ++i) cin >> a[i]; for(int i = 1; i<=m; ++i){ int x,y,z; cin >> x >> y >> z; adj[x].pb(y,z), adj[y].pb(x,z); } memset(dist,0x3f,sizeof(dist)); for(int i = 0; i<k; ++i) dijkstra(dist[i],a[i]); memset(dp,0x3f,sizeof(dp)); for(int i = 1; i<=n; ++i) dp[0][i]=0; for(int mask = 1; mask<(1<<k); ++mask){ for(int i = 0; i<k; ++i) if((mask>>i)&1) for(int j = 1; j<=n; ++j) dp[mask][j]=min(dp[mask][j],dp[mask^(1<<i)][j]+dist[i][j]); dijkstra2(dp[mask]); } for(int i = 1; i<=n; ++i) rs=min(rs,dp[(1<<k)-1][i]); cout << rs; }

컴파일 시 표준 에러 (stderr) 메시지

cities.cpp: In function 'int main()':
cities.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cities.cpp:51:45: note: in expansion of macro 'fo'
   51 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
cities.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cities.cpp:51:45: note: in expansion of macro 'fo'
   51 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...