답안 #472183

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
472183 2021-09-13T09:05:08 Z elgamalsalman Toll (BOI17_toll) C++14
0 / 100
3000 ms 5416 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second

typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

ll k, n, m, o;
vvii  adj;

ll getToll(ll u, ll v) {
  //cerr << "// getToll(" << u << ", " << v << ")\n";
  if (u == v) return 0;
  if (u/5 >= v/5) return -1;

  ll minToll = -1;
  for (ii edge : adj[u]) {
    ll currToll = getToll(edge.fi, v);
    if (currToll == -1) continue;
    currToll += edge.se;
    if (minToll == -1 || currToll < minToll) minToll = currToll;
  }

  return minToll;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  cin >> k >> n >> m >> o;
  adj.assign(n + 20, vii());
  for (ll i = 0; i < m; i++) {
    ll a, b, t;
    cin >> a >> b >> t;
    adj[a].push_back({b, t});
  }
  
  for (ll i = 0; i < o; i++) {
    ll a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    cout << getToll(a, b) << '\n';
  }
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3069 ms 5416 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3068 ms 4036 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3069 ms 5416 KB Time limit exceeded
2 Halted 0 ms 0 KB -