Submission #1519228


Source Code Expand

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define all(c) begin(c),end(c)
const ll INF = 1e18;

struct edge { ll from, to, cost; };
edge es[2000];
ll d[1000];
bool flag = false;;
int V, E;	//頂点、辺数
//頂点sからの最短d
void bellmanford(int s) {
	int count = 0;
	rep(i, V)d[i] = INF;
	d[s] = 0;
	while (count<n) {
		bool update = false;
		rep(i, E) {
			edge e = es[i];
			if (d[e.from] != INF&&d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if (!update)break;
		count++;
	}
	if (count == V)flag = true;
}

//負の閉路->true
bool find_negative_loop() {
	memset(d, 0, sizeof(d));
	rep(i, V) {
		rep(j, E) {
			edge e = es[j];
			if (d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				if (i == V - 1)return true;
			}
		}
	}
	return false;
}

int main() {
	cin.sync_with_stdio(false);
	cin >> V >> E;
	rep(i, E) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--; c = -c;
		es[i].from = a; es[i].to = b; es[i].cost = c;
	}
	bellmanford(0);
	if (flag) {
		cout << "inf" << endl;
		return 0;
	}
	bellmanford(0);
	cout << -d[V - 1] << endl;

	return 0;
}

Submission Info

Submission Time
Task D - Score Attack
User agis
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1349 Byte
Status CE

Compile Error

./Main.cpp: In function ‘void bellmanford(int)’:
./Main.cpp:21:15: error: ‘n’ was not declared in this scope
  while (count<n) {
               ^