Submission #736260

# Submission time Handle Problem Language Result Execution time Memory
736260 2023-05-05T11:26:13 Z rahidilbayramli Alias (COCI21_alias) C++17
50 / 70
21 ms 852 KB
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define vl vector<ll>
#define sl set<ll>
#define conn continue
#define tests while(t--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f first
#define s second
using namespace std;
const int sz = 1e4+5, inf = 1e9+7;
int dist[sz];
int n, m, i, j, l, c, q;
vector<pii>g[sz];
string a, b;
void dijkstra(int src)
{
    for(i = 1; i <= n; i++)    dist[i] = inf;
    dist[src] = 0;
    using T = pair<ll, int>;
    priority_queue<T, vector<T>, greater<T>>pq;
    pq.push({0ll, src});
    while(!pq.empty())
    {
        int node;
        ll cdist;
        tie(cdist, node) = pq.top();
        pq.pop();
        if(cdist != dist[node])    continue;
        for(const pii u : g[node])
        {
            if(cdist + u.s < dist[u.f])
            {
                dist[u.f] = cdist + u.s;
                pq.push({dist[u.f], u.f});
            }
        }
    }
}
int main()
{
    int x, y;
    map<string, ll>mp;
    set<string>st;
    cin >> n >> m;
    for(i = 0; i < m; i++)
    {
        cin >> a >> b >> c;
        l = st.size();
        st.insert(a);
        if(l != st.size())    mp[a] = st.size();
        l = st.size();
        st.insert(b);
        if(l != st.size())    mp[b] = st.size();
        x = mp[a], y = mp[b];
        g[x].pb({y, c});
    }
    cin >> q;
    while(q--)
    {
        cin >> a >> b;
        x = mp[a], y = mp[b];
        dijkstra(x);
        if(dist[y] == inf)    cout << "Roger\n";
        else    cout << dist[y] << "\n";
    }
}

Compilation message

alias.cpp: In function 'int main()':
alias.cpp:56:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         if(l != st.size())    mp[a] = st.size();
      |            ~~^~~~~~~~~~~~
alias.cpp:59:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         if(l != st.size())    mp[b] = st.size();
      |            ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 540 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 16 ms 596 KB Output is correct
4 Incorrect 21 ms 596 KB Output isn't correct
5 Correct 6 ms 724 KB Output is correct
6 Correct 7 ms 724 KB Output is correct
7 Incorrect 6 ms 852 KB Output isn't correct