Code Submission Evaluation System Login

Datatähti 2016 alku

Start:2015-09-28 00:00:00
End:2015-10-12 00:00:00
 

Tasks | Scoreboard | Statistics


CSES - Datatähti 2016 alku - Results
History
2015-10-02 19:09:16100
2015-10-02 19:08:2961
2015-10-02 19:06:0424
2015-10-01 20:29:4924
2015-10-01 20:29:18
2015-10-01 20:24:2724
Task:Lennot
Sender:fergusq
Submission time:2015-10-01 20:29:18
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp:9:16: error: '::main' must return 'int'
 long long main() {
                ^
input/code.cpp: In function 'int main()':
input/code.cpp:37:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (long long i = 0; i < v[s].size(); i++) {
                           ^

Code

#include <iostream>
#include <queue>

using namespace std;

#define fromto(var, from, to) for (long long var = from; var < to; var++)
#define INF 999999999

long long main() {
	cin.sync_with_stdio(false);
	long long n, m;
	cin >> n >> m;
	
	vector<pair<long long,long long> > v[1+2*n];
	
	fromto(i, 0, m) {
		long long a, b, h;
		cin >> a >> b >> h;
		v[a].push_back(make_pair(n+b, h));
		v[n+a].push_back(make_pair(b, 0));
	}
	
	priority_queue<pair<long long,long long> > q;
	long long t[1+2*n], e[1+2*n];
	
	fromto(i, 1, 1+2*n) t[i] = 0;
	
	for (long long i = 1; i <= n*2; i++) e[i] = INF;
	e[1] = 0;
	q.push(make_pair(0,1));
	while (!q.empty()) {
		long long x = -q.top().first;
		long long s = q.top().second;
		q.pop();
		if (t[s]) continue;
		t[s] = 1;
		for (long long i = 0; i < v[s].size(); i++) {
			long long u = v[s][i].first;
			if (x+v[s][i].second < e[u]) {
				e[u] = x+v[s][i].second;
				q.push(make_pair(-e[u],u));
			}
		}
	}
	
	cout << min(e[n], e[2*n]) << endl;
}