Submission #61741

#TimeUsernameProblemLanguageResultExecution timeMemory
61741ansol4328주유소 (KOI16_gas)C++98
18 / 100
1440 ms66560 KiB
#include<stdio.h> #include<vector> #include<queue> #include<memory.h> using namespace std; typedef pair<long long,long long> P; int n, gas[2502]; vector<P> lst[2502]; priority_queue<P, vector<P>, greater<P> > PQ; long long dxy[2502][2502]; void make_dxy(int s) { int v; bool check[2502]; for(int i=1 ; i<=n ; i++) dxy[s][i]=1e18; dxy[s][s]=0; memset(check,false,sizeof(check)); PQ.push(P(0,s)); while(!PQ.empty()) { do { v=PQ.top().second; PQ.pop(); }while(!PQ.empty() && check[v]); check[v]=true; for(int i=0 ; i<lst[v].size() ; i++) { if(dxy[s][lst[v][i].first]>dxy[s][v]+lst[v][i].second*gas[s] && !check[lst[v][i].first]) { dxy[s][lst[v][i].first]=dxy[s][v]+lst[v][i].second*gas[s]; PQ.push(P(dxy[s][lst[v][i].first],lst[v][i].first)); } } } } long long dijkstra() { int v; long long dist[2502]; bool check[2502]; for(int i=1 ; i<=n ; i++) dist[i]=1e18; dist[1]=0; memset(check,false,sizeof(check)); PQ.push(P(0,1)); while(!PQ.empty()) { do { v=PQ.top().second; PQ.pop(); }while(!PQ.empty() && check[v]); if(v==n) break; check[v]=true; for(int i=0 ; i<lst[v].size() ; i++) { if(dist[lst[v][i].first]>dist[v]+lst[v][i].second && !check[lst[v][i].first]) { dist[lst[v][i].first]=dist[v]+lst[v][i].second; PQ.push(P(dist[lst[v][i].first],lst[v][i].first)); } } } return dist[n]; } int main() { int m, a, b, c; scanf("%d %d",&n,&m); for(int i=1 ; i<=n ; i++) scanf("%d",&gas[i]); for(int i=0 ; i<m ; i++) { scanf("%d %d %d",&a,&b,&c); lst[a].push_back(P(b,c)); lst[b].push_back(P(a,c)); } for(int i=1 ; i<=n ; i++) make_dxy(i); for(int i=1 ; i<=n ; i++) { lst[i].clear(); for(int j=1 ; j<=n ; j++) { if(i!=j) lst[i].push_back(P(j,dxy[i][j])); } } printf("%lld",dijkstra()); return 0; }

Compilation message (stderr)

gas.cpp: In function 'void make_dxy(int)':
gas.cpp:30:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0 ; i<lst[v].size() ; i++)
                       ~^~~~~~~~~~~~~~
gas.cpp: In function 'long long int dijkstra()':
gas.cpp:59:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0 ; i<lst[v].size() ; i++)
                       ~^~~~~~~~~~~~~~
gas.cpp: In function 'int main()':
gas.cpp:74:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~
gas.cpp:75:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1 ; i<=n ; i++) scanf("%d",&gas[i]);
                               ~~~~~^~~~~~~~~~~~~~
gas.cpp:78:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d",&a,&b,&c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
#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...