# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
851739 | fcmalkcin | Alias (COCI21_alias) | C++17 | 50 ms | 4176 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define endl "\n"
const ll maxn=1e5+54;
const ll mod =998244353 ;
const ll base=3e18;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
ll cnt;
map<string, ll> ind_map;
ll ind(string x) {
if (ind_map.find(x) == ind_map.end())
ind_map[x] = cnt++;
return ind_map[x];
}
ll n, m, q;
vector<pll> e[maxn];
ll dist[maxn];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
if (fopen("guard.in", "r"))
{
freopen("guard.in", "r", stdin);
freopen("guard.out", "w", stdout);
}
cin >> n >> m;
for (int i = 0; i < m; i++) {
ll t;
string x, y;
cin >> x >> y >> t;
e[ind(x)].push_back(make_pair(ind(y), t));
}
cin >> q;
for (ll i = 0; i < q; i++) {
string x, y;
cin >> x >> y;
set<pll> s;
memset(dist, -1, sizeof dist);
dist[ind(x)] = 0;
s.insert(pll(0ll, ind(x)));
while (!s.empty()) {
pll curr = *s.begin();
s.erase(curr);
ll curr_ind = curr.second;
for (ll j = 0; j < (ll)e[curr_ind].size(); j++) {
ll nxt = e[curr_ind][j].first;
ll d = e[curr_ind][j].second;
if (dist[nxt] == -1 || dist[nxt] > dist[curr_ind] + d) {
s.erase(pll(dist[nxt], nxt));
dist[nxt] = dist[curr_ind] + d;
s.insert(pll(dist[nxt], nxt));
}
}
}
if (dist[ind(y)] == -1)
cout << "Roger" << endl;
else
cout << dist[ind(y)] << endl;
}
return 0;
}
/*
5 1
1 2
4
+ 1
?
+ 1
?
*/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |