Skip to content

Instantly share code, notes, and snippets.

@IKKO-Ohta
Last active May 16, 2017 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IKKO-Ohta/f57a41b0171414aadc4fdaa408cf2ce4 to your computer and use it in GitHub Desktop.
Save IKKO-Ohta/f57a41b0171414aadc4fdaa408cf2ce4 to your computer and use it in GitHub Desktop.
ABC61[D] _WF_Score Attack
#define REP(i,n) for (int i=0;i<(n);i++)
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX_N = 5000;
const long long MIN = -1000000000000;
long long d[MAX_N][MAX_N]; //距離表
int n,m;
void init(){
REP(i,n){
REP(j,n){
if (i == j) d[i][j] = 0;
else d[i][j] = MIN;
}
}
}
void warshall_floyd(){
REP(k,n){
REP(i,n){
REP(j,n){
d[i][j] = max(d[i][j],d[i][k]+d[k][j]);
}
}
}
}
int main(){
cin >> n >> m;
init();
REP(i,m){
int a,b,c;
cin >> a >> b >> c;
a--;b--;
d[a][b]=c;
}
warshall_floyd();
if(d[0][0] > 0) cout << "inf" << endl;
else cout << d[0][n-1] << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment