結果
| 問題 |
No.2712 Play more!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-31 14:40:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 3,274 bytes |
| コンパイル時間 | 2,253 ms |
| コンパイル使用メモリ | 215,596 KB |
| 最終ジャッジ日時 | 2025-02-20 17:22:39 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 WA * 1 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template <typename T> using min_priority_queue = priority_queue<T,vector<T>,greater<T>>;
template<typename T>
void printv(vector<T> &v){
bool b = false;
for(auto i : v){
if(b) cout << " ";
else b = true;
cout << i;
}
cout << endl;
}
template <typename T>
bool chmin(T &a, const T& b) {
if (a > b) {
a = b; // aをbで更新
return true;
}
return false;
}
template <typename T>
bool chmax(T &a, const T& b) {
if (a < b) {
a = b; // aをbで更新
return true;
}
return false;
}
void yn(bool b){
if(b) cout << "Yes" << endl;
else cout << "No" << endl;
}
bool debug;
bool randomInput;
bool debugOutput;
int numOfTestCase;
using ans_type = int;
void input(){
if(numOfTestCase > 1){
;
}
if(randomInput){
}
else{
}
return;
}
void output_input(){
;
}
ans_type calc(){
int N, M;
cin >> N >> M;
vector<int> A(N);
for(auto &a : A) cin >> a;
vector<tuple<int,int,int>> V(M);
for(auto &[a, b, c] : V){
cin >> a >> b >> c;
a--; b--;
}
vector<vector<pair<int64_t, int>>> G(2*N);
vector<vector<pair<int64_t, int>>> Ginv(2*N);
for(auto[a, b, c] : V){
G[2*a+1].push_back({c, 2*b});
Ginv[2*b].push_back({c, 2*a+1});
}
for(int i = 0; i < N; i++){
G[2*i].push_back({-A[i], 2*i+1});
Ginv[2*i+1].push_back({-A[i], 2*i});
}
int64_t INF = 1001002003004005006;
vector<int64_t> D(2*N, INF);
D[0] = 0;
for(int i = 0; i < 2*N-1; i++){
for(int j = 0; j < 2*N-1; j++){
for(auto[d, k] : G[j]){
chmin(D[k], D[j]+d);
}
}
}
vector<int> W;
for(int j = 0; j < 2*N-1; j++){
for(auto[d, k] : G[j]){
if(D[k] > D[j]+d){
W.push_back(k);
}
}
}
vector<bool> check(2*N, false);
queue<int> q;
check[2*N-1] = true;
q.push(2*N-1);
while(q.size()){
int pos = q.front();
q.pop();
for(auto [e, j] : Ginv[pos]){
if(check[j]) continue;
check[j] = true;
q.push(j);
}
}
for(int i : W){
if(check[i]){
cout << "inf" << endl;
return 0;
}
}
cout << -D[2*N-1] << endl;
//for(auto i : D) cout << i << " ";cout << endl;
return ans_type();
}
ans_type calc_simple(){
return ans_type();
}
void output(ans_type ans){
return;
}
int main(){
debug = 0;
randomInput = 0;
debugOutput = 0;
numOfTestCase = 1;
srand(time(NULL));
cout << fixed << setprecision(12);
if(numOfTestCase == 0) cin >> numOfTestCase;
if(debug){
for(int i = 0; i < numOfTestCase; i++){
input();
ans_type ans = calc();
ans_type ansSimple = calc_simple();
if(ans != ansSimple){
output_input();
output(ans);
output(ansSimple);
}
}
}
else{
for(int i = 0; i < numOfTestCase; i++){
input();
output(calc());
}
}
return 0;
}