Last active
July 11, 2017 15:24
-
-
Save IvanIsCoding/72d1419ac31278c16397f66403e10b8a to your computer and use it in GitHub Desktop.
Seletiva IOI 2014
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Ivan Carvalho | |
| // Tráfego - Seletiva IOI - OBI 2014 | |
| #include <bits/stdc++.h> | |
| #define MAXN 50010 | |
| using namespace std; | |
| typedef pair<int,int> ii; | |
| struct aresta{ | |
| int alvo,d,g,r; | |
| }; | |
| int N,M; | |
| vector<aresta> grafo[MAXN]; | |
| int processado[MAXN]; | |
| int main(){ | |
| scanf("%d %d",&N,&M); | |
| for(int i=1;i<=M;i++){ | |
| int u; | |
| aresta davez; | |
| scanf("%d %d %d %d %d",&u,&davez.alvo,&davez.d,&davez.g,&davez.r); | |
| grafo[u].push_back(davez); | |
| } | |
| priority_queue<ii, vector<ii> ,greater<ii> > Dijkstra; | |
| Dijkstra.push(MP(0,1)); | |
| while(!Dijkstra.empty()){ | |
| ii davez = Dijkstra.top(); | |
| Dijkstra.pop(); | |
| int dist = davez.first, v = davez.second; | |
| if(v == N){ | |
| printf("%d\n",dist); | |
| return 0; | |
| } | |
| if(processado[v]) continue; | |
| processado[v] = 1; | |
| for(int i = 0;i<grafo[v].size();i++){ | |
| int u = grafo[v][i].alvo, d = grafo[v][i].d, g = grafo[v][i].g, r = grafo[v][i].r; | |
| int instante = dist + d; | |
| if(instante % (g+r) >= g){ | |
| instante = instante - (instante % (g+r)) + g + r; | |
| } | |
| Dijkstra.push(MP(instante,u)); | |
| } | |
| } | |
| printf("-1\n"); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment