답안 #979618

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
979618 2024-05-11T08:57:39 Z vjudge1 자매 도시 (APIO20_swap) C++17
컴파일 오류
0 ms 0 KB
#include <time.h>
#include <cstdlib>
#include <stack>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <map>
#include <set>
#include <iterator>
#include <deque>
#include <queue>
#include <sstream>
#include <array>
#include <string>
#include <tuple>
#include <chrono>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <list>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <bitset>


#include "swap.h"

#include <cassert>
#include <cstdio>

#include <string>
#include <vector>

// using namespace std;

vector<pair<int, int>> g[200005];
pair<int, int> p[200005];
map<pair<int, int>, int> mp, pos;
set<pair<int, int>> st;
int N, M;
int getMinimumFuelCapacity(int X, int Y){
    X++;
    Y++;
    if(N <= 3)
        return -1;
    int mx = 0;
    if(X != 1) mx = mp[{1, X}];
    if(Y != 1) mx = max(mx, mp[{1, Y}]);


    if(X != 1) st.erase({mp[{1, X}], pos[{1, X}]});
    if(Y != 1) st.erase({mp[{1, Y}], pos[{1, Y}]});
    
    pair<int, int> p = *st.begin();
    st.erase(st.begin());
    if(X != 1 && Y != 1){
        st.insert(p);
        if(X != 1) st.insert({mp[{1, X}], pos[{1, X}]});
        if(Y != 1) st.insert({mp[{1, Y}], pos[{1, Y}]});
        return max(mx, p.first);
    }
    else{
        pair<int, int> p1 = *st.begin();
        st.insert(p1);
        st.insert(p);
        if(X != 1) st.insert({mp[{1, X}], pos[{1, X}]});
        if(Y != 1) st.insert({mp[{1, Y}], pos[{1, Y}]});
        return max({mx, p.first, p1.first});
    }
}
int main() {
  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 a = U[i] + 1, b = V[i] + 1, c = W[i] + 1;
    g[a].push_back({b, c});
    g[b].push_back({a, c});
    mp[{a, b}] = c;
    mp[{b, a}] = c;

    pos[{a, b}] = i + 1;
    pos[{b, a}] = i + 1;

    st.insert({c, i + 1});
  }

  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:39:1: error: 'vector' does not name a type
   39 | vector<pair<int, int>> g[200005];
      | ^~~~~~
swap.cpp:40:1: error: 'pair' does not name a type
   40 | pair<int, int> p[200005];
      | ^~~~
swap.cpp:41:1: error: 'map' does not name a type
   41 | map<pair<int, int>, int> mp, pos;
      | ^~~
swap.cpp:42:1: error: 'set' does not name a type
   42 | set<pair<int, int>> st;
      | ^~~
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:50:21: error: 'mp' was not declared in this scope; did you mean 'mx'?
   50 |     if(X != 1) mx = mp[{1, X}];
      |                     ^~
      |                     mx
swap.cpp:51:29: error: 'mp' was not declared in this scope; did you mean 'mx'?
   51 |     if(Y != 1) mx = max(mx, mp[{1, Y}]);
      |                             ^~
      |                             mx
swap.cpp:51:21: error: 'max' was not declared in this scope; did you mean 'std::max'?
   51 |     if(Y != 1) mx = max(mx, mp[{1, Y}]);
      |                     ^~~
      |                     std::max
In file included from /usr/include/c++/10/algorithm:62,
                 from swap.cpp:25:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: 'std::max' declared here
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
swap.cpp:54:16: error: 'st' was not declared in this scope; did you mean 'std'?
   54 |     if(X != 1) st.erase({mp[{1, X}], pos[{1, X}]});
      |                ^~
      |                std
swap.cpp:54:26: error: 'mp' was not declared in this scope; did you mean 'mx'?
   54 |     if(X != 1) st.erase({mp[{1, X}], pos[{1, X}]});
      |                          ^~
      |                          mx
swap.cpp:54:38: error: 'pos' was not declared in this scope; did you mean 'pow'?
   54 |     if(X != 1) st.erase({mp[{1, X}], pos[{1, X}]});
      |                                      ^~~
      |                                      pow
swap.cpp:55:16: error: 'st' was not declared in this scope; did you mean 'std'?
   55 |     if(Y != 1) st.erase({mp[{1, Y}], pos[{1, Y}]});
      |                ^~
      |                std
swap.cpp:55:26: error: 'mp' was not declared in this scope; did you mean 'mx'?
   55 |     if(Y != 1) st.erase({mp[{1, Y}], pos[{1, Y}]});
      |                          ^~
      |                          mx
swap.cpp:55:38: error: 'pos' was not declared in this scope; did you mean 'pow'?
   55 |     if(Y != 1) st.erase({mp[{1, Y}], pos[{1, Y}]});
      |                                      ^~~
      |                                      pow
swap.cpp:57:5: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
   57 |     pair<int, int> p = *st.begin();
      |     ^~~~
      |     std::pair
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/deque:60,
                 from /usr/include/c++/10/stack:60,
                 from swap.cpp:3:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'std::pair' declared here
  211 |     struct pair
      |            ^~~~
swap.cpp:57:10: error: expected primary-expression before 'int'
   57 |     pair<int, int> p = *st.begin();
      |          ^~~
swap.cpp:58:5: error: 'st' was not declared in this scope; did you mean 'std'?
   58 |     st.erase(st.begin());
      |     ^~
      |     std
swap.cpp:60:19: error: 'p' was not declared in this scope
   60 |         st.insert(p);
      |                   ^
swap.cpp:61:31: error: 'mp' was not declared in this scope; did you mean 'mx'?
   61 |         if(X != 1) st.insert({mp[{1, X}], pos[{1, X}]});
      |                               ^~
      |                               mx
swap.cpp:61:43: error: 'pos' was not declared in this scope; did you mean 'pow'?
   61 |         if(X != 1) st.insert({mp[{1, X}], pos[{1, X}]});
      |                                           ^~~
      |                                           pow
swap.cpp:62:31: error: 'mp' was not declared in this scope; did you mean 'mx'?
   62 |         if(Y != 1) st.insert({mp[{1, Y}], pos[{1, Y}]});
      |                               ^~
      |                               mx
swap.cpp:62:43: error: 'pos' was not declared in this scope; did you mean 'pow'?
   62 |         if(Y != 1) st.insert({mp[{1, Y}], pos[{1, Y}]});
      |                                           ^~~
      |                                           pow
swap.cpp:63:16: error: 'max' was not declared in this scope; did you mean 'std::max'?
   63 |         return max(mx, p.first);
      |                ^~~
      |                std::max
In file included from /usr/include/c++/10/algorithm:62,
                 from swap.cpp:25:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: 'std::max' declared here
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
swap.cpp:66:14: error: expected primary-expression before 'int'
   66 |         pair<int, int> p1 = *st.begin();
      |              ^~~
swap.cpp:67:19: error: 'p1' was not declared in this scope; did you mean 'y1'?
   67 |         st.insert(p1);
      |                   ^~
      |                   y1
swap.cpp:68:19: error: 'p' was not declared in this scope
   68 |         st.insert(p);
      |                   ^
swap.cpp:69:31: error: 'mp' was not declared in this scope; did you mean 'mx'?
   69 |         if(X != 1) st.insert({mp[{1, X}], pos[{1, X}]});
      |                               ^~
      |                               mx
swap.cpp:69:43: error: 'pos' was not declared in this scope; did you mean 'pow'?
   69 |         if(X != 1) st.insert({mp[{1, X}], pos[{1, X}]});
      |                                           ^~~
      |                                           pow
swap.cpp:70:31: error: 'mp' was not declared in this scope; did you mean 'mx'?
   70 |         if(Y != 1) st.insert({mp[{1, Y}], pos[{1, Y}]});
      |                               ^~
      |                               mx
swap.cpp:70:43: error: 'pos' was not declared in this scope; did you mean 'pow'?
   70 |         if(Y != 1) st.insert({mp[{1, Y}], pos[{1, Y}]});
      |                                           ^~~
      |                                           pow
swap.cpp:71:16: error: 'max' was not declared in this scope; did you mean 'std::max'?
   71 |         return max({mx, p.first, p1.first});
      |                ^~~
      |                std::max
In file included from /usr/include/c++/10/algorithm:62,
                 from swap.cpp:25:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: 'std::max' declared here
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
swap.cpp: In function 'int main()':
swap.cpp:81:5: error: 'g' was not declared in this scope
   81 |     g[a].push_back({b, c});
      |     ^
swap.cpp:83:5: error: 'mp' was not declared in this scope
   83 |     mp[{a, b}] = c;
      |     ^~
swap.cpp:86:5: error: 'pos' was not declared in this scope; did you mean 'pow'?
   86 |     pos[{a, b}] = i + 1;
      |     ^~~
      |     pow
swap.cpp:89:5: error: 'st' was not declared in this scope; did you mean 'std'?
   89 |     st.insert({c, i + 1});
      |     ^~
      |     std