Submission #851737

# Submission time Handle Problem Language Result Execution time Memory
851737 2023-09-20T14:00:50 Z fcmalkcin Alias (COCI21_alias) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>

using namespace std;


#define pb  push_back
#define ll  long long
#define pll pair<ll,ll>
#define ff  first
#define ss  second
#define endl "\n"
const ll maxn=1e5+54;
const ll mod =998244353   ;
const ll base=3e18;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


ll cnt;
map<string, ll> ind_map;

ll ind(string x) {
    if (ind_map.find(x) == ind_map.end())
        ind_map[x] = cnt++;
    return ind_map[x];
}

ll n, m, q;
vector<pii> e[maxn];

ll dist[maxn];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if (fopen("guard.in", "r"))
    {
        freopen("guard.in", "r", stdin);
        freopen("guard.out", "w", stdout);
    }
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        ll t;
        string x, y;
        cin >> x >> y >> t;
        e[ind(x)].push_back(pii(ind(y), t));
    }
    cin >> q;
    for (ll i = 0; i < q; i++) {
        string x, y;
        cin >> x >> y;
        set<pli> s;
        memset(dist, -1, sizeof dist);
        dist[ind(x)] = 0;
        s.insert(pli(0, ind(x)));
        while (!s.empty()) {
            pli curr = *s.begin();
            s.erase(curr);
            ll curr_ind = curr.second;
            for (ll j = 0; j < (ll)e[curr_ind].size(); j++) {
                ll nxt = e[curr_ind][j].first;
                ll d = e[curr_ind][j].second;
                if (dist[nxt] == -1 || dist[nxt] > dist[curr_ind] + d) {
                    s.erase(pli(dist[nxt], nxt));
                    dist[nxt] = dist[curr_ind] + d;
                    s.insert(pli(dist[nxt], nxt));
                }
            }
        }
        if (dist[ind(y)] == -1)
            cout << "Roger" << endl;
        else
            cout << dist[ind(y)] << endl;
    }
    return 0;
}
/*
5 1
1 2
4
+ 1
?
+ 1
?
*/

Compilation message

alias.cpp:29:8: error: 'pii' was not declared in this scope
   29 | vector<pii> e[maxn];
      |        ^~~
alias.cpp:29:11: error: template argument 1 is invalid
   29 | vector<pii> e[maxn];
      |           ^
alias.cpp:29:11: error: template argument 2 is invalid
alias.cpp: In function 'int main()':
alias.cpp:47:19: error: request for member 'push_back' in 'e[ind(std::__cxx11::basic_string<char>(x))]', which is of non-class type 'int'
   47 |         e[ind(x)].push_back(pii(ind(y), t));
      |                   ^~~~~~~~~
alias.cpp:47:29: error: 'pii' was not declared in this scope
   47 |         e[ind(x)].push_back(pii(ind(y), t));
      |                             ^~~
alias.cpp:53:13: error: 'pli' was not declared in this scope; did you mean 'pll'?
   53 |         set<pli> s;
      |             ^~~
      |             pll
alias.cpp:53:16: error: template argument 1 is invalid
   53 |         set<pli> s;
      |                ^
alias.cpp:53:16: error: template argument 2 is invalid
alias.cpp:53:16: error: template argument 3 is invalid
alias.cpp:56:11: error: request for member 'insert' in 's', which is of non-class type 'int'
   56 |         s.insert(pli(0, ind(x)));
      |           ^~~~~~
alias.cpp:57:19: error: request for member 'empty' in 's', which is of non-class type 'int'
   57 |         while (!s.empty()) {
      |                   ^~~~~
alias.cpp:58:16: error: expected ';' before 'curr'
   58 |             pli curr = *s.begin();
      |                ^~~~~
      |                ;
alias.cpp:59:15: error: request for member 'erase' in 's', which is of non-class type 'int'
   59 |             s.erase(curr);
      |               ^~~~~
alias.cpp:59:21: error: 'curr' was not declared in this scope
   59 |             s.erase(curr);
      |                     ^~~~
alias.cpp:61:48: error: request for member 'size' in 'e[curr_ind]', which is of non-class type 'int'
   61 |             for (ll j = 0; j < (ll)e[curr_ind].size(); j++) {
      |                                                ^~~~
alias.cpp:62:37: error: invalid types 'int[long long int]' for array subscript
   62 |                 ll nxt = e[curr_ind][j].first;
      |                                     ^
alias.cpp:63:35: error: invalid types 'int[long long int]' for array subscript
   63 |                 ll d = e[curr_ind][j].second;
      |                                   ^
alias.cpp:65:23: error: request for member 'erase' in 's', which is of non-class type 'int'
   65 |                     s.erase(pli(dist[nxt], nxt));
      |                       ^~~~~
alias.cpp:67:23: error: request for member 'insert' in 's', which is of non-class type 'int'
   67 |                     s.insert(pli(dist[nxt], nxt));
      |                       ^~~~~~
alias.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen("guard.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
alias.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen("guard.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~