제출 #649807

#제출 시각아이디문제언어결과실행 시간메모리
649807mychecksedadRobot (JOI21_ho_t4)C++17
24 / 100
726 ms165660 KiB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;

struct Edge{
    int nxt, c, e;
};

int n, m;
ll dist[N][2];
vector<Edge> g[N];
multiset<int> color[N];
map<int, ll> s[N];
void solve(){
    cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int u, v, c, p; cin >> u >> v >> c >> p;
        g[u].pb({v, c, p});
        g[v].pb({u, c, p});
        color[u].insert(c);
        color[v].insert(c);
        s[u][c] += p;
        s[v][c] += p;
    }

    for(int i = 1; i <= n; ++i) dist[i][0] = dist[i][1] = 1e18;

    priority_queue<array<ll, 3>> q;
    vector<bool> vis(n + 1);
    dist[n][0] = 0;
    q.push({0, n, -1});

    while(!q.empty()){
        int v = q.top()[1], cc = q.top()[2]; q.pop();
        if(vis[v]) continue;
        vis[v] = 1;
        // cout << v << '\n';
        for(auto E: g[v]){
            int u = E.nxt, c = E.c; ll e = E.e;
            ll val = s[u][c];

            if(cc == c || color[u].count(c) == 1) e = 0;

            ll D = min(dist[v][0], dist[v][1]);

            if(D + e < dist[u][0]){
                dist[u][0] = D + e;
                q.push({-dist[u][0], u, -1});
            }
            if(e > 0 && D + val - e < dist[u][1]){
                dist[u][1] = D + val - e;
                q.push({-dist[u][1], u, c});
            }
        }
    }
    if(min(dist[1][0], dist[1][1]) == 1e18) cout << -1;
    else cout << min(dist[1][0], dist[1][1]);
}   





int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    int T = 1, aa;
    // cin >> T;aa=T;
    while(T--){
        // cout << "Case #" << aa-T << ": ";
        solve();
        cout << '\n';
    }
    return 0;
 
}

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

Main.cpp: In function 'int main()':
Main.cpp:78:16: warning: unused variable 'aa' [-Wunused-variable]
   78 |     int T = 1, aa;
      |                ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...