Submission #723222

#TimeUsernameProblemLanguageResultExecution timeMemory
723222CookieRobot (JOI21_ho_t4)C++14
34 / 100
3076 ms39328 KiB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("WINTER.inp");
ofstream fout("WINTER.out");
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;

const ll mod = 1e9 + 7;
const int mxn = 1e5, mxm = 2e5;
struct th{
    int v, color, cost, id;
};
struct ch{
    int s; ll d; int last;
    
};
struct cmp{
    bool operator()(const ch &a, const ch &b){
        return(a.d > b.d);
    }
};
int n, m;
vt<th>adj[mxn + 1];
vt<ll>d[mxn + 1];
vt<int>edge[mxn + 1];
ll sm[mxm + 1];
int find(int u, int x){ 
    if(x == 0)return(0);
    return(lower_bound(edge[u].begin(), edge[u].end(), x) - edge[u].begin() + 1);
}
signed main(){
    
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    forr(i, 1, m + 1){
        int a, b, c, p; cin >> a >> b >> c >> p;
        adj[a].pb({b, c, p, i}); adj[b].pb({a, c, p, i});
        edge[a].pb(i); edge[b].pb(i);
    }
    forr(i, 1, n + 1){
        sort(edge[i].begin(), edge[i].end());
        
        d[i].resize(edge[i].size() + 1);
        for(int j = 0; j <= edge[i].size(); j++){
            d[i][j] = 1e18;
        }
        
    }
   
    priority_queue<ch, vt<ch>, cmp>pq; 
    d[1][0] = 0; pq.push({1, d[1][0], 0});
    while(!pq.empty()){
        
        auto [u, dd, last] = pq.top(); pq.pop();
        if(d[u][find(u, last)] != dd)continue;
        for(auto [v, color, cost, id]: adj[u]){
            if(last == id)continue;
            sm[color] += cost;
        }
        for(auto [v, color, cost, id]: adj[u]){
            if(last == id)continue;
            if(d[v][0] > dd + sm[color] - cost){
                d[v][0] = dd + sm[color] - cost;
                pq.push({v, d[v][0], 0});
            }
            int idv = find(v, id);
           
            if(d[v][idv] > dd + cost){
                d[v][idv] = dd + cost;
                pq.push({v, d[v][idv], id});
            }
            
        }
        for(auto [v, color, cost, id]: adj[u]){
            sm[color]  = 0;
        }
    }
    ll res = 1e18;
    for(int i = 0; i <=edge[n].size(); i++){
        res = min(res, d[n][i]);
    }
    if(res == 1e18){
        cout << -1;
    }else{
        cout << res;
    }
    return(0);
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:55:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(int j = 0; j <= edge[i].size(); j++){
      |                        ~~^~~~~~~~~~~~~~~~~
Main.cpp:65:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   65 |         auto [u, dd, last] = pq.top(); pq.pop();
      |              ^
Main.cpp:67:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   67 |         for(auto [v, color, cost, id]: adj[u]){
      |                  ^
Main.cpp:71:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   71 |         for(auto [v, color, cost, id]: adj[u]){
      |                  ^
Main.cpp:85:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   85 |         for(auto [v, color, cost, id]: adj[u]){
      |                  ^
Main.cpp:90:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |     for(int i = 0; i <=edge[n].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...