# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
447903 | Jasiekstrz | Alias (COCI21_alias) | C++17 | 24 ms | 460 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=1e3;
const long long INF=1e18L+7;
int idit=0;
map<string,int> id;
vector<pair<int,int>> e[N+10];
long long d[N+10];
int getid(string x)
{
if(id.find(x)==id.end())
id[x]=++idit;
return id[x];
}
void dijkstra(int x)
{
priority_queue<pair<long long,int>> pq;
d[x]=0;
pq.emplace(0,x);
while(!pq.empty())
{
auto [dd,y]=pq.top();
pq.pop();
if(d[y]!=-dd)
continue;
for(auto [v,c]:e[y])
{
if(d[v]>d[y]+c)
{
d[v]=d[y]+c;
pq.emplace(-d[v],v);
}
}
}
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m,q;
cin>>n>>m;
for(int i=1;i<=m;i++)
{
string a,b;
int c;
cin>>a>>b>>c;
e[getid(a)].emplace_back(getid(b),c);
}
cin>>q;
while(q--)
{
string a,b;
cin>>a>>b;
for(int i=1;i<=n;i++)
d[i]=INF;
dijkstra(getid(a));
if(d[getid(b)]==INF)
cout<<"Roger\n";
else
cout<<d[getid(b)]<<"\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |