Submission #1591263


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr ll INF=1e18;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

struct Edge{
	int src,dst;
	ll weight;
	Edge(){}
	Edge(int s,int d,ll w):src(s),dst(d),weight(w){}
};
using Graph=vector<vector<Edge>>;

bool BellmanFord(const Graph& g,int src,vl& dist)
{
	int n=g.size();
	dist[src]=0;
	rep(k,n-1)
		rep(u,n) for(auto e:g[u])
			if(dist[e.dst]>dist[e.src]+e.weight)
				dist[e.dst]=dist[e.src]+e.weight;
	rep(k,n)
		rep(u,n) for(auto e:g[u])
			if(dist[e.dst]>dist[e.src]+e.weight){
				dist[e.src]=dist[e.src]+e.weight;
				if(e.dst==n-1)
					return false;
			}
	return true;
}

void BuildPath(const vi& prev,int dst,vi& path)
{
	for(int v=dst;v!=-1;v=prev[v])
		path.push_back(v);
	reverse(all(path));
}

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n,m;cin>>n>>m&&n|m;){
		Graph g(n);
		rep(i,m){
			int u,v,w; cin>>u>>v>>w; u--,v--;
			g[u].emplace_back(u,v,-w);
		}

		vl cost(n,INF);
		if(!BellmanFord(g,0,cost))
			cout<<"inf"<<endl;
		else
			cout<<-cost[n-1]<<endl;
	}
}

Submission Info

Submission Time
Task D - Score Attack
User lyoz
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2738 Byte
Status WA
Exec Time 15 ms
Memory 384 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 26
WA × 4
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_1.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt, subtask_1_19.txt, subtask_1_2.txt, subtask_1_20.txt, subtask_1_21.txt, subtask_1_22.txt, subtask_1_23.txt, subtask_1_24.txt, subtask_1_25.txt, subtask_1_26.txt, subtask_1_27.txt, subtask_1_3.txt, subtask_1_4.txt, subtask_1_5.txt, subtask_1_6.txt, subtask_1_7.txt, subtask_1_8.txt, subtask_1_9.txt
Case Name Status Exec Time Memory
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
subtask_1_1.txt AC 2 ms 256 KB
subtask_1_10.txt AC 1 ms 256 KB
subtask_1_11.txt AC 2 ms 256 KB
subtask_1_12.txt WA 7 ms 384 KB
subtask_1_13.txt AC 3 ms 256 KB
subtask_1_14.txt WA 6 ms 384 KB
subtask_1_15.txt AC 6 ms 384 KB
subtask_1_16.txt AC 1 ms 256 KB
subtask_1_17.txt AC 1 ms 256 KB
subtask_1_18.txt AC 6 ms 256 KB
subtask_1_19.txt AC 12 ms 384 KB
subtask_1_2.txt AC 5 ms 384 KB
subtask_1_20.txt AC 4 ms 256 KB
subtask_1_21.txt AC 7 ms 384 KB
subtask_1_22.txt AC 15 ms 384 KB
subtask_1_23.txt AC 1 ms 256 KB
subtask_1_24.txt AC 9 ms 384 KB
subtask_1_25.txt AC 3 ms 256 KB
subtask_1_26.txt AC 6 ms 384 KB
subtask_1_27.txt AC 6 ms 384 KB
subtask_1_3.txt AC 4 ms 256 KB
subtask_1_4.txt AC 5 ms 384 KB
subtask_1_5.txt WA 3 ms 256 KB
subtask_1_6.txt WA 6 ms 384 KB
subtask_1_7.txt AC 5 ms 384 KB
subtask_1_8.txt AC 5 ms 384 KB
subtask_1_9.txt AC 1 ms 256 KB