이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ;
ll ab (ll x ) { return (x>0?x:-x); }
const int N = 300005 ;
const ll oo = 1e18 ;
ll dist [N] ;
set<int> dogs;
// int par[N];
ll n , m ;
ll B[N] , P[N] ;
ll dijkstra(){
priority_queue< pll, vector <pll> , greater<pll> > pq;
pq.push( mp(0,0) ) ;
for(int i = 1 ; i <= m ; i++ )dist[i] = oo ;
dist[0] = 0LL ;
// vector<int> choosen ;
while ( !pq.empty() ){
int u = pq.top().se ;
ll d = pq.top().fi ;
pq.pop() ;
if( dogs.find ( u ) != dogs.end() )
dogs.erase( dogs.find (u) ) ;
if( u == 1 )return dist[1] ;
if( dist[u] < d )continue ;
for(int v : dogs ){
d = dist[u] + ab(B[u]-B[v]) / P[u] ;
if(ab(B[u]-B[v])%P[u] == 0LL && dist[v] > d ){
// cout << u << " " << v << endl;
dist[v] = d;
pq.push( {d ,v} );
}
}
} return -1 ;
}
void input(){
// fastio ;
// ifstream cin("in.in") ;
cin >> n >> m ;
for(int i = 0 ; i < m ; i++ ){
cin >> B[i] >> P[i] ;
if(i)dogs.insert(i) ;
}
}
int main(){
input() ;
cout << dijkstra( ) << endl;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |