# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
736265 | rahidilbayramli | Alias (COCI21_alias) | C++17 | 23 ms | 468 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define vl vector<ll>
#define sl set<ll>
#define all(v) v.begin(), v.end()
#define f first
#define s second
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define tests while(t--)
using namespace std;
const ll sz = 1010, inf = 1e15;
ll dist[sz];
vector<pair<ll, int>>adj[sz];
int n, m, i, j;
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>>q;
q.push({0ll, src});
while(!q.empty())
{
int node;
ll cdist;
tie(cdist, node) = q.top();
q.pop();
if(cdist != dist[node]) continue;
for(auto u : adj[node])
{
if(cdist + u.s < dist[u.f])
{
dist[u.f] = cdist + u.s;
q.push({dist[u.f], u.f});
}
}
}
}
int main()
{
ll c, l, x, y, q;
string a, b;
cin >> n >> m;
set<string>st;
map<string, ll>mp;
for(i = 0; i < m; i++)
{
cin >> a >> b >> c;
l = st.size();
st.insert(a);
if(st.size() != l)
mp[a] = st.size();
l = st.size();
st.insert(b);
if(st.size() != l)
mp[b] = st.size();
x = mp[a], y = mp[b];
adj[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";
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |