답안 #330294

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
330294 2020-11-24T14:14:37 Z BeanZ Ceste (COCI17_ceste) C++14
0 / 160
3 ms 748 KB
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 2005;
const int lg = 18;
const int mod = 1e9 + 7;
const long long oo = 1e18;
const int lim = 1e6;
struct viet{
    ll u, c, t;
};
struct lpl{
    ll u, c, t;
    bool operator <(const lpl &o) const{
        return c > o.c;
    }
};
vector<viet> node[N];
ll best[N], dp[N];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("A.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    ll n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++){
        ll u, v, c, t;
        cin >> u >> v >> c >> t;
        node[u].push_back({v, c, t});
        node[v].push_back({u, c, t});
    }
    for (int i = 1; i <= n; i++){
        best[i] = 1e18;
        dp[i] = 1e18;
    }
    best[1] = 0;
    dp[1] = 0;
    priority_queue<lpl> pq;
    pq.push({1, 0, 0});
    while (pq.size()){
        lpl x = pq.top();
        pq.pop();
        if (x.t > best[x.u]) continue;
        for (auto j : node[x.u]){
            if ((x.t + j.t) < best[j.u]){
                best[j.u] = x.t + j.t;
                dp[j.u] = min(dp[j.u], (x.t + j.t) * (x.c + j.c));
                pq.push({j.u, x.c + j.c, x.t + j.t});
            }
        }
    }
    for (int i = 2; i <= n; i++){
        if (dp[i] >= 1e17) cout << -1 << endl;
        else cout << dp[i] << endl;
    }
}
/*
*/

Compilation message

ceste.cpp: In function 'int main()':
ceste.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   26 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ceste.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   27 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 748 KB Output isn't correct
2 Halted 0 ms 0 KB -