답안 #872353

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
872353 2023-11-13T00:15:29 Z scrge Robot (JOI21_ho_t4) C++17
0 / 100
531 ms 84104 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    int n, m; cin >> n >> m;
    vector<vector<array<int, 3>>> adj(n);
    vector<map<int, int>> col_cost(n);
    for(int i = 0; i < m; i++){
        int u, v, c, p; cin >> u >> v >> c >> p;
        u--, v--;
        adj[u].push_back({v, c, p}); 
        adj[v].push_back({u, c, p}); 
        col_cost[u][c] += p;
        col_cost[v][c] += p;
    }

    /*for(int i = 0; i < n; i++){
        cout << i+1 << ": ";
        for(auto [c, p]: col_cost[i])
            printf("(%d %d) ", c, p);
        cout << endl;
    }*/

    vector<map<int, int>> dp(n);
    priority_queue<array<int, 5>> q;
    q.push({0, 0, 0, 0});
    while(q.size()){
        auto [d, u, c, p, pre] = q.top(); q.pop();
        d = -d;
        //printf("d: %d, u: %d, c: %d, p: %d\n", d, u+1, c, p);
        if(dp[u].count(c)) continue;
        dp[u][c] = d;
        for(auto [v, c1, p1]: adj[u]){
            // change everything else
            if(v == pre) continue;
            //cout << v << " " << c1 << " " << col_cost[u][c1]-p1-((c==c1)*p) << endl;
            q.push({-(d+col_cost[u][c1]-((c==c1)*p)-p1), v, c1, p1, u});
            // change just this edge
            q.push({-(d+p1), v, 0, p1});
        }
    }

    int ans = LLONG_MAX;
    for(auto [x, res]: dp[n-1])
        ans = min(ans, res);
    cout << (ans == LLONG_MAX ? -1 : ans) << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 7 ms 1180 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Incorrect 531 ms 84104 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 501 ms 61092 KB Output is correct
2 Incorrect 151 ms 19600 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 7 ms 1180 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Incorrect 531 ms 84104 KB Output isn't correct
10 Halted 0 ms 0 KB -