답안 #698586

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
698586 2023-02-13T22:34:43 Z Gital Autobus (COCI22_autobus) C++11
15 / 70
1000 ms 394424 KB
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
ll dp[75];
vector<pair<ll,ll>> v[75];
bool checked[75];
int n,m;
priority_queue<pair<pair<ll,ll>,ll>,vector<pair<pair<ll,ll>,ll>>,greater<pair<pair<ll,ll>,ll>>> pq;
int k,q;
int main () {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        ll a,b,c; cin >> a >> b >> c;
        v[a].push_back({c,b});
    }
    cin >> k >> q;
    for(int j = 0; j < q; j++) {
        ll st,en; cin >> st >> en;
        for(int i = 0; i < 75; i++) {
            checked[i] = false;
            dp[i] = -1;
        }
        dp[st] = 0;
        pq.push({{0,st},0});
        while(!pq.empty()) {
            ll a = pq.top().first.first;
            ll b = pq.top().first.second;
            ll cnt = pq.top().second;
            pq.pop();
            /*if(checked[b]) continue;
            checked[b] = true;*/
            if(cnt >= k) continue;
            for(int i = 0; i < v[b].size(); i++) {
                if(dp[v[b][i].second] == -1 || dp[v[b][i].second] > a + v[b][i].first) {
                    dp[v[b][i].second] = max((ll)0,a + v[b][i].first);
                }
                pq.push({{a + v[b][i].first,v[b][i].second},cnt+1});
            }
        }
        cout << dp[en] << endl;
    }
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:35:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |             for(int i = 0; i < v[b].size(); i++) {
      |                            ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 9 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 64 ms 488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 336 KB Output is correct
2 Correct 24 ms 396 KB Output is correct
3 Correct 172 ms 392 KB Output is correct
4 Correct 203 ms 428 KB Output is correct
5 Execution timed out 1082 ms 564 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 9 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 64 ms 488 KB Output is correct
7 Execution timed out 1099 ms 394424 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 9 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 64 ms 488 KB Output is correct
7 Correct 4 ms 336 KB Output is correct
8 Correct 24 ms 396 KB Output is correct
9 Correct 172 ms 392 KB Output is correct
10 Correct 203 ms 428 KB Output is correct
11 Execution timed out 1082 ms 564 KB Time limit exceeded
12 Halted 0 ms 0 KB -