# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
943770 | 2024-03-11T21:02:56 Z | svaz | Alias (COCI21_alias) | C++17 | 358 ms | 640 KB |
#include<bits/stdc++.h> using namespace std; int INF=99999999; void dijkstra(vector<vector<pair<int, int> > > &grafo,int origen,vector<int> &distancias) { int n=grafo.size(); vector<bool> visitados(n,false); distancias[origen]=0; for(int i=0;i<n;i++)///recorrer todos los nodos { int minNodo=-1,minDist=INF; for(int j=0;j<n;j++) { if(!visitados[j] && distancias[j]<minDist) { minDist=distancias[j]; minNodo=j; } } if(minNodo==-1) break; visitados[minNodo]=true; for(int a=0;a<grafo[minNodo].size();a++) { int hacia=grafo[minNodo][a].first; int peso=grafo[minNodo][a].second; if(!visitados[hacia] && distancias[minNodo]+peso<distancias[hacia]) { distancias[hacia]=distancias[minNodo]+peso; } } } } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n,m; cin>>n>>m; string x,y; long long t; map<string,vector<pair<string,long long> > >db; for(int i=0;i<m;i++){ cin>>x>>y>>t; db[x].push_back(make_pair(y,t)); } int q; cin>>q; for(int i=0;i<q;i++){ cin>>x>>y; map<string,long long>dist; queue<string>q; dist[x]=0; q.push(x); while(!q.empty()){ string next=q.front(); q.pop(); vector<pair<string,long long> >conexiones=db[next]; for(int i=0;i<conexiones.size();i++){ string recuerdo=conexiones[i].first; long long tiempo=conexiones[i].second; if(dist.count(recuerdo)==0){ dist[recuerdo]=dist[next]+tiempo; q.push(recuerdo); } else dist[recuerdo]=min(dist[recuerdo],dist[next]+tiempo); } } if(dist.count(y))cout<<dist[y]<<"\n"; else cout<<"Roger\n"; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Incorrect | 1 ms | 348 KB | Output isn't correct |
3 | Incorrect | 298 ms | 620 KB | Output isn't correct |
4 | Incorrect | 358 ms | 640 KB | Output isn't correct |
5 | Correct | 4 ms | 604 KB | Output is correct |
6 | Correct | 5 ms | 604 KB | Output is correct |
7 | Correct | 3 ms | 604 KB | Output is correct |