# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
671927 | Kenpar | Alias (COCI21_alias) | C++17 | 93 ms | 620 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define endl '\n'
const ll MOD = 1e9+7;
const ll INF = 1e18;
const ll MAX = 2500;
void solve(){
map<string,int> toInt;
set<string> used;
int n,m;
cin>>n>>m;
int cur = 0;
vector<vector<pair<ll,ll>>> edges(n);
for(int i = 0; i < m; i++){
string a,b; ll c;
cin>>a>>b>>c;
int aInd, bInd;
if(!used.count(a)){
aInd = cur;
toInt[a] = cur;
cur++;
used.insert(a);
}else{
aInd = toInt[a];
}
if(!used.count(b)){
bInd = cur;
toInt[b] = cur;
cur++;
used.insert(b);
}else{
bInd = toInt[b];
}
edges[aInd].push_back({bInd, c});
}
int q;
cin>>q;
for(int i = 0; i < q; i++){
vector<ll> dist(n, INF);
string aTemp, bTemp; cin>>aTemp>>bTemp;
int a = toInt[aTemp], b = toInt[bTemp];
priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> pq;
pq.push({0,a});
while(!pq.empty()){
pair<ll,ll> top = pq.top();
pq.pop();
if(dist[top.second] <= top.first) continue;
dist[top.second] = top.first;
for(pair<ll,ll> edge : edges[top.second]){
pq.push({top.first + edge.second, edge.first});
}
}
if(dist[b] == INF) cout<<"Roger";
else cout<<dist[b];
cout<<endl;
}
}
int main()
{
cin.tie(NULL);
ios::sync_with_stdio(NULL);
int t = 1;
//cin>>t;
int temp = t;
while(t--){
//cout<<"Case #"<<temp - t<<" > "<<endl;
solve();
cout<<endl;
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |