답안 #919789

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
919789 2024-02-01T16:15:27 Z abcdefghijk123 Alias (COCI21_alias) C++14
50 / 70
16 ms 604 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;

const int MM = 1002;
int intN, intM;
//int dis[MM]; 
vector<pi> adj[MM]; 
//bool vis[MM];
int dis[MM];
bool vis[MM];

int function1(int start, int end) {
    fill(dis, dis + intN, 0x3f3f3f3f);
    fill(vis, vis + intN, false);

    priority_queue<pi, vector<pi>, greater<pi>> q;
    dis[start] = 0;  
    q.push({0, start});
    while(!q.empty()){
        auto [d, u] = q.top(); 
        q.pop();
        if(vis[u]) continue;
        vis[u] = true;
        for(auto [v, w] : adj[u]){
            if(dis[v] > dis[u] + w){
                dis[v] = dis[u] + w;
                q.push({dis[v], v});
            }
        }
    }
    
    return dis[end];
    
}

int main() {
    
    cin.sync_with_stdio(0);
    cin.tie(0);
    
    unordered_map<string, int> mp;
    cin >> intN >> intM;
    
    for (int i = 0; i < intM; i++) {
        string x, y, z;
        cin >> x >> y >> z;
        if(!mp.count(x)) mp[x] = mp.size();
        if(!mp.count(y)) mp[y] = mp.size();
        adj[mp[x]].push_back({mp[y],stoi(z)});
        //adj[y].push_back({x,z});
    }
    
    int intQ;
    cin >> intQ;

    for (int i = 0; i < intQ; i++) {
        string x, y;
        cin >> x >> y;
        int index = mp[x];
        int index1 = mp[y];
        int aaa = function1(index,index1);
        if(aaa > 1000000000) {
            cout << "Roger" << "\n";
        } else {
            cout << aaa << "\n";
        }
    }
    
 
}

Compilation message

alias.cpp: In function 'int function1(int, int)':
alias.cpp:21:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   21 |         auto [d, u] = q.top();
      |              ^
alias.cpp:25:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   25 |         for(auto [v, w] : adj[u]){
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 11 ms 348 KB Output is correct
4 Incorrect 16 ms 604 KB Output isn't correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Incorrect 2 ms 604 KB Output isn't correct