Submission #982357

#TimeUsernameProblemLanguageResultExecution timeMemory
982357simona1230Swapping Cities (APIO20_swap)C++17
13 / 100
130 ms25836 KiB
#include "swap.h" #include <bits/stdc++.h> using namespace std; int maxx,minn,maxw; int n,m,x,y; vector<int> v[100001],w[100001],num[100001]; pair<int,int> p[100001]; bool sec=1; struct edge { int x,y,d; edge(){} edge(int _x,int _y,int _d) { x=_x; y=_y; d=_d; } bool operator<(const edge&e)const { return e.d<d; } }; void init(int N, int M,std::vector<int> U, std::vector<int> V, std::vector<int> W) { minn=N; n=N; m=M; for(int i=0;i<m;i++) { if(U[i]!=0)sec=0; maxw=max(maxw,W[i]); v[U[i]].push_back(V[i]); v[V[i]].push_back(U[i]); w[U[i]].push_back(W[i]); w[V[i]].push_back(W[i]); num[U[i]].push_back(i); num[V[i]].push_back(i); maxx=max(maxx,(int)v[U[i]].size()); maxx=max(maxx,(int)v[V[i]].size()); p[i]={W[i],V[i]}; } sort(p,p+m); for(int i=0;i<n;i++) { minn=min(minn,(int)v[i].size()); } } int d[1024][1024]; void dijkstra() { for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { d[i][j]=1e9+1; } } priority_queue<edge> q; q.push({x,y,0}); d[x][y]=0; while(q.size()) { edge e=q.top(); q.pop(); if(d[e.x][e.y]>=e.d) { for(int i=0;i<v[e.x].size();i++) { for(int j=0;j<v[e.y].size();j++) { int nb1=v[e.x][i],nb2=v[e.y][j]; if(num[e.x][i]==num[e.y][j]||nb1==nb2)continue; int wg=max(w[e.x][i],w[e.y][j]); if(d[nb1][nb2]>=max(d[e.x][e.y],wg)) { d[nb1][nb2]=max(d[e.x][e.y],wg); q.push({nb1,nb2,d[nb1][nb2]}); } } } } } } int getMinimumFuelCapacity(int X, int Y) { x=X; y=Y; if(maxx<=2) { if(minn==1)return -1; return maxw; } if(sec) { if(x==0||y==0) { if(x>y)swap(x,y); int i1=0,i2=1; if(p[0].second==y)i1=2; if(p[1].second==y)i2=2; int ans=max(p[i1].first,p[i2].first); ans=max(ans,w[y][0]); return ans; } int ans=p[0].first; if(p[0].second==x||p[0].second==y)ans=p[1].first; if(p[1].second==x||p[1].second==y)ans=p[2].first; ans=max(ans,w[x][0]); ans=max(ans,w[y][0]); return ans; } int ans=d[y][x]; if(ans==1e9+1)ans=-1; return ans; } /* 5 4 0 1 1 0 2 2 0 3 3 0 4 4 4 0 1 0 2 0 3 0 4 */

Compilation message (stderr)

swap.cpp: In function 'void dijkstra()':
swap.cpp:78:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |             for(int i=0;i<v[e.x].size();i++)
      |                         ~^~~~~~~~~~~~~~
swap.cpp:80:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |                 for(int j=0;j<v[e.y].size();j++)
      |                             ~^~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...