# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
410282 | mat_v | Robot (JOI21_ho_t4) | C++14 | 292 ms | 34728 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<ll,int>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
struct edge{
int x;
int boja;
ll v;
};
ll maks = 1e9;
struct node{
int cale;
int x;
ll v;
};
bool operator < (const node &a, const node &b){
return a.v < b.v;
}
bool operator > (const node &a, const node &b){
return a.v > b.v;
}
int n,m;
vector<edge> graf[100005];
vector<pii> pravi[100005];
ll dist[100005];
bool cmp(edge a, edge b){
if(a.boja < b.boja)return 1;
return 0;
}
map<pii,bool>post;
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
maks *= maks;
cin >> n >> m;
// n = 1005;
// m = 2005;
ff(i,1,m){
int a,b,c,d;
// a = rnd()%n;
// b = rnd()%n;
// a++;
// b++;
// c = rnd()%m;
// c++;
// d = rnd()%1000000;
// if(post[{a,b}]){
// a = (rnd()%n) + 1;
// b = (rnd()%n) + 1;
// }
// post[{a,b}] = post[{b,a}] = 1;
cin >> a >> b >> c >> d;
graf[a].pb({b,c,d});
graf[b].pb({a,c,d});
}
ff(i,1,n)sort(graf[i].begin(), graf[i].end(), cmp);
ff(r,1,n){
int len = graf[r].size();
if(len == 0)continue;
int last = 0;
ll sum = 0;
int koji = r;
ff(i,0,len - 1){
if(graf[koji][i].boja != graf[koji][last].boja){
ff(j,last,i-1){
if(j < i-1){
int p1 = graf[koji][j].x;
int p2 = graf[koji][i - 1].x;
ll duz = sum - graf[koji][i - 1].v;
pravi[p1].pb({duz,p2});
if(i-1 != last){
int p1 = graf[koji][j].x;
int p2 = graf[koji][i - 2].x;
ll duz = sum - graf[koji][i - 2].v;
pravi[p1].pb({duz,p2});
}
}
else{
if(last != i-1){
int p1 = graf[koji][i - 1].x;
int p2 = graf[koji][i - 2].x;
ll duz = sum - graf[koji][i - 2].v;
pravi[p1].pb({duz,p2});
}
}
ll duz1 = graf[koji][j].v;
int gde = graf[koji][j].x;
duz1 = min(duz1, sum - graf[koji][j].v);
pravi[koji].pb({duz1,gde});
}
last = i;
sum = graf[koji][i].v;
}
else{
sum += graf[koji][i].v;
}
}
ff(j,last,len-1){
if(j < len-1){
int p1 = graf[koji][j].x;
int p2 = graf[koji][len - 1].x;
ll duz = sum - graf[koji][len - 1].v;
pravi[p1].pb({duz,p2});
}
else{
if(last != len-1){
int p1 = graf[koji][len - 1].x;
int p2 = graf[koji][len - 2].x;
ll duz = sum - graf[koji][len - 2].v;
pravi[p1].pb({duz,p2});
}
}
ll duz1 = graf[koji][j].v;
int gde = graf[koji][j].x;
duz1 = min(duz1, sum - graf[koji][j].v);
pravi[koji].pb({duz1,gde});
}
}
priority_queue<pii> pq;
dist[1] = 0;
ff(i,2,n)dist[i] = maks;
pq.push({0,1});
while(!pq.empty()){
pii sta = pq.top();
pq.pop();
for(auto c:pravi[sta.yy]){
int koji = c.yy;
if(dist[koji] > c.xx - sta.xx){
dist[koji] = c.xx - sta.xx;
pq.push({-dist[koji],koji});
}
}
}
if(dist[n] < maks)cout << dist[n] << "\n";
else cout << -1 << "\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |