답안 #985683

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
985683 2024-05-18T14:32:38 Z yoav_s 자매 도시 (APIO20_swap) C++17
17 / 100
2000 ms 23100 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> p;
typedef pair<ll, p> tri;
typedef vector<ll> v;
typedef vector<v> vv;
typedef vector<p> vp;
typedef vector<tri> vtri;
typedef vector<vtri> vvtri;
typedef vector<vvtri> vvvtri;
typedef vector<vv> vvv;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
typedef vector<p> vp;
typedef vector<vp> vvp;
typedef vector<vvp> vvvp;
typedef vector<vvvp> vvvvp;
#define double long double
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;

const ll mod = 1e9 + 7;
const ll INF = 1e18;

#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define loop(a) for (ll i = 0; i < a; i++)
#define setmin(a, b) a = min(a, b)
#define setmax(a, b) a = max(a, b)
#define all(v) v.begin(), v.end()

#include "swap.h"
ll res = -1;
vvp graph;
ll maxW = -INF;
ll N;

void init(int Nn, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
    N = Nn;
    graph = vvp(N);
    for (ll i = 0; i < M; i++)
    {
      graph[U[i]].eb(V[i], W[i]);
      graph[V[i]].eb(U[i], W[i]);
      maxW = max(maxW, (ll)W[i]);
    }
}

int getMinimumFuelCapacity(int X, int Y) {
  ll mini = 0, maxi = maxW + 1;
  while (mini < maxi)
  {
    ll mid = (mini + maxi) / 2;
    vv curGraph(N);
    for (ll i= 0 ; i < N; i++)
    {
      for (auto x : graph[i]) if (x.s <= mid) curGraph[i].pb(x.f);
    }
    v accessibleVertices;
    stack<ll> dfs;
    vb visited(N, false);
    dfs.push(X);
    while (!dfs.empty())
    {
      auto top = dfs.top();
      dfs.pop();
      if (visited[top]) continue;
      visited[top] = true;
      accessibleVertices.pb(top);
      for (ll x : curGraph[top]) dfs.push(x);
    }
    bool poss = false;
    if (visited[Y])
    {
      for (ll x : accessibleVertices) if (curGraph[x].size() >= 3) poss = true;
      ll edgeCount = 0;
      for (ll x : accessibleVertices) edgeCount += curGraph[x].size();
      edgeCount /= 2;
      if (edgeCount >= accessibleVertices.size()) poss = true;
    }
    if (poss)
    {
      maxi = mid;
    }
    else
    {
      mini = mid + 1;
    
    }
  }
  if (mini > maxW) return -1;
  return mini;
}
/*
int main() {
  int N, M;
  assert(2 == scanf("%d %d", &N, &M));
  
  std::vector<int> U(M), V(M), W(M);
  for (int i = 0; i < M; ++i) {
    assert(3 == scanf("%d %d %d", &U[i], &V[i], &W[i]));
  }

  int Q;
  assert(1 == scanf("%d", &Q));

  std::vector<int> X(Q), Y(Q);
  for (int i = 0; i < Q; ++i) {
    assert(2 == scanf("%d %d", &X[i], &Y[i]));
  }

  init(N, M, U, V, W);
  
  std::vector<int> minimum_fuel_capacities(Q);
  for (int i = 0; i < Q; ++i) {
    minimum_fuel_capacities[i] = getMinimumFuelCapacity(X[i], Y[i]);
  }

  for (int i = 0; i < Q; ++i) {
    printf("%d\n", minimum_fuel_capacities[i]);
  }
  
  return 0;
}
/**/

Compilation message

swap.cpp:131:1: warning: "/*" within comment [-Wcomment]
  131 | /**/
      |  
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:85:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |       if (edgeCount >= accessibleVertices.size()) poss = true;
      |           ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 9 ms 600 KB Output is correct
6 Correct 11 ms 348 KB Output is correct
7 Correct 12 ms 348 KB Output is correct
8 Correct 18 ms 604 KB Output is correct
9 Correct 434 ms 14556 KB Output is correct
10 Correct 1168 ms 17768 KB Output is correct
11 Correct 1470 ms 17228 KB Output is correct
12 Correct 1693 ms 18432 KB Output is correct
13 Execution timed out 2054 ms 18568 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Execution timed out 2021 ms 23100 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 9 ms 600 KB Output is correct
6 Correct 11 ms 348 KB Output is correct
7 Correct 12 ms 348 KB Output is correct
8 Correct 18 ms 604 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 10 ms 604 KB Output is correct
11 Correct 9 ms 348 KB Output is correct
12 Correct 13 ms 600 KB Output is correct
13 Correct 11 ms 628 KB Output is correct
14 Correct 11 ms 344 KB Output is correct
15 Correct 13 ms 604 KB Output is correct
16 Correct 8 ms 444 KB Output is correct
17 Correct 8 ms 412 KB Output is correct
18 Correct 13 ms 600 KB Output is correct
19 Correct 9 ms 344 KB Output is correct
20 Correct 9 ms 600 KB Output is correct
21 Correct 12 ms 348 KB Output is correct
22 Correct 9 ms 604 KB Output is correct
23 Correct 11 ms 348 KB Output is correct
24 Correct 21 ms 604 KB Output is correct
25 Correct 24 ms 604 KB Output is correct
26 Correct 18 ms 604 KB Output is correct
27 Correct 7 ms 348 KB Output is correct
28 Correct 17 ms 696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 9 ms 600 KB Output is correct
7 Correct 11 ms 348 KB Output is correct
8 Correct 12 ms 348 KB Output is correct
9 Correct 18 ms 604 KB Output is correct
10 Correct 434 ms 14556 KB Output is correct
11 Correct 1168 ms 17768 KB Output is correct
12 Correct 1470 ms 17228 KB Output is correct
13 Correct 1693 ms 18432 KB Output is correct
14 Execution timed out 2054 ms 18568 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 9 ms 600 KB Output is correct
6 Correct 11 ms 348 KB Output is correct
7 Correct 12 ms 348 KB Output is correct
8 Correct 18 ms 604 KB Output is correct
9 Correct 434 ms 14556 KB Output is correct
10 Correct 1168 ms 17768 KB Output is correct
11 Correct 1470 ms 17228 KB Output is correct
12 Correct 1693 ms 18432 KB Output is correct
13 Execution timed out 2054 ms 18568 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 9 ms 600 KB Output is correct
7 Correct 11 ms 348 KB Output is correct
8 Correct 12 ms 348 KB Output is correct
9 Correct 18 ms 604 KB Output is correct
10 Correct 434 ms 14556 KB Output is correct
11 Correct 1168 ms 17768 KB Output is correct
12 Correct 1470 ms 17228 KB Output is correct
13 Correct 1693 ms 18432 KB Output is correct
14 Execution timed out 2054 ms 18568 KB Time limit exceeded
15 Halted 0 ms 0 KB -