제출 #710428

#제출 시각아이디문제언어결과실행 시간메모리
710428Ronin13Robot (JOI21_ho_t4)C++14
0 / 100
139 ms103764 KiB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax = 1000001;
vector <pll> g[nmax];
ll d[nmax];
vector <bool> used(nmax);

int cnt = 0;
vector <vector <pair<pii, int> > >G(nmax);
int m;
bool process(vector <pii> cur, int v){
    ll s = 0;
    vector <int> vv;
    for(auto to : cur){
        vv.pb(cnt++);
        vv.pb(cnt++);
        s += (ll)to.f;
    }
    for(int j = 0; j < cur.size(); j++){
        int x = vv[j * 2], y = vv[j * 2 + 1];
        g[4 * m + v].pb({y, cur[j].f});
        g[4 * m + v].pb({x, s - cur[j].f});
        g[x].pb({4 * m + cur[j].s, 0});
        g[y].pb({4 * m + cur[j].s, 0});
    }
    for(int j = 0; j < cur.size(); j++){
        int x = vv[j * 2 + 1];
        if(j == cur.size() - 1){
            if(cur.size() == 1) continue;
            int o = cur.size() - 2;
            int l = vv[o * 2];
            g[x].pb({l, s - cur[j].f - cur[j - 1].f});
        }
        else{
            int y = cur.size() - 1;
            int o = vv[y * 2];
            g[x].pb({o, s - cur[j].f - cur.back().f});
        }
    }
}

int main(){
    int n; cin >> n;
    cin >> m;
    for(int i = 1; i <= m; i++){
        int u, v, c, p; cin >> u >> v >> c >> p;
        G[u].pb({{c, p}, v});
        G[v].pb({{c, p}, u});
    }
    for(int v = 1; v <= n; v++){
        if(G[v].empty()) continue;
        sort(G[v].begin(), G[v].end());
        vector <pii> cur;
        cur.epb(G[v][0].f.s, G[v][0].s);
        for(int i = 1; i < G[v].size(); i++){
            if(G[v][i].f.f == G[v][i - 1].f.f){
                cur.epb(G[v][i].f.s, G[v][i].s);
            }
            else{
                process(cur, v);
                cur.clear();
                cur.epb(G[v][i].f.s, G[v][i].s);
            }
        }
        process(cur, v);
    }
    for(int i = 0; i <= 4 * m + n; i++){
        d[i] = 1e18;
    }
    d[4 * m + 1] = 0;
    priority_queue<pll> q;
    q.push({0, 4 * m + 1});
    while(!q.empty()){
        int v = q.top().s;
        q.pop();
        if(used[v]) continue;
        used[v] = true;
        for(auto ed : g[v]){
            int to = ed.f;
            ll len = ed.s;
            if(d[to] > d[v] + len){
                d[to] = d[v] + len;
                q.push({-d[to], to});
            }
        }
    }
    if(d[4 * m + n] == 1e18)
        cout << -1;
    else
    cout << d[4 * m + n];
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'bool process(std::vector<std::pair<int, int> >, int)':
Main.cpp:27:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int j = 0; j < cur.size(); j++){
      |                    ~~^~~~~~~~~~~~
Main.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int j = 0; j < cur.size(); j++){
      |                    ~~^~~~~~~~~~~~
Main.cpp:36:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         if(j == cur.size() - 1){
      |            ~~^~~~~~~~~~~~~~~~~
Main.cpp:48:1: warning: no return statement in function returning non-void [-Wreturn-type]
   48 | }
      | ^
Main.cpp: In function 'int main()':
Main.cpp:63:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         for(int i = 1; i < G[v].size(); i++){
      |                        ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...