Submission #1279370
Source Code Expand
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>
#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>
#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif
using namespace std;
namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define VV(T) vector<vector< T > >
template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
stringstream ss;
ss << f;
ss >> t;
}
#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()
#define MOD 1000000007LL
#define EPS 1e-8
void mainmain(){
const LL INF = 1LL << 60;
int n, m;
scanf("%d%d", &n, &m);
VV(pll) G(n), rG(n);
for(int i = 0; i < m; ++i){
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
--a;
--b;
G[a].emplace_back(b, c);
rG[b].emplace_back(a, c);
}
vector<char> reachable(n);
queue<int> q;
q.push(n - 1);
reachable[n - 1] = 1;
while(!q.empty()){
int u = q.front();
q.pop();
for(cauto p : rG[u]){
int v = p.first;
if(!reachable[v]){
reachable[v] = 1;
q.push(v);
}
}
}
vector<LL> scr(n, -INF);
scr[0] = 0;
bool updated = true;
for(int z = 0; z < n + 5; ++z){
updated = false;
for(int i = 0; i < n; ++i){
if(scr[i] == -INF){ continue; }
for(cauto p : G[i]){
int v = p.first;
LL c = scr[i] + p.second;
if(scr[v] < c){
scr[v] = c;
updated |= reachable[v];
}
}
}
}
if(updated){ puts("inf"); }
else{ printf("%lld\n", scr.back()); }
}
}
int main() try{
// ios::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(4);
mainmain();
}
catch(...){}
Submission Info
Submission Time |
|
Task |
D - Score Attack |
User |
climpet |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
2800 Byte |
Status |
AC |
Exec Time |
7 ms |
Memory |
384 KB |
Compile Error
./Main.cpp: In function ‘void {anonymous}::mainmain()’:
./Main.cpp:85:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
^
./Main.cpp:89:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &a, &b, &c);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 400 |
Status |
|
|
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 |
AC |
4 ms |
384 KB |
subtask_1_13.txt |
AC |
2 ms |
256 KB |
subtask_1_14.txt |
AC |
5 ms |
384 KB |
subtask_1_15.txt |
AC |
7 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 |
3 ms |
384 KB |
subtask_1_19.txt |
AC |
6 ms |
384 KB |
subtask_1_2.txt |
AC |
4 ms |
384 KB |
subtask_1_20.txt |
AC |
2 ms |
256 KB |
subtask_1_21.txt |
AC |
4 ms |
384 KB |
subtask_1_22.txt |
AC |
7 ms |
384 KB |
subtask_1_23.txt |
AC |
1 ms |
256 KB |
subtask_1_24.txt |
AC |
4 ms |
384 KB |
subtask_1_25.txt |
AC |
2 ms |
256 KB |
subtask_1_26.txt |
AC |
4 ms |
384 KB |
subtask_1_27.txt |
AC |
4 ms |
384 KB |
subtask_1_3.txt |
AC |
3 ms |
384 KB |
subtask_1_4.txt |
AC |
4 ms |
384 KB |
subtask_1_5.txt |
AC |
2 ms |
256 KB |
subtask_1_6.txt |
AC |
5 ms |
384 KB |
subtask_1_7.txt |
AC |
3 ms |
384 KB |
subtask_1_8.txt |
AC |
4 ms |
384 KB |
subtask_1_9.txt |
AC |
1 ms |
256 KB |