結果

問題 No.1364 [Renaming] Road to Cherry from Zelkova
ユーザー tnakao0123tnakao0123
提出日時 2021-01-25 19:46:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,118 bytes
コンパイル時間 1,420 ms
コンパイル使用メモリ 100,264 KB
実行使用メモリ 12,648 KB
最終ジャッジ日時 2023-09-04 16:29:13
合計ジャッジ時間 7,199 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,860 KB
testcase_01 AC 3 ms
5,804 KB
testcase_02 AC 3 ms
5,928 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 26 ms
7,936 KB
testcase_24 AC 29 ms
6,776 KB
testcase_25 AC 68 ms
9,708 KB
testcase_26 AC 104 ms
11,104 KB
testcase_27 AC 79 ms
9,612 KB
testcase_28 AC 49 ms
8,560 KB
testcase_29 AC 78 ms
9,444 KB
testcase_30 AC 51 ms
8,764 KB
testcase_31 AC 36 ms
8,468 KB
testcase_32 AC 61 ms
8,880 KB
testcase_33 AC 105 ms
10,676 KB
testcase_34 AC 106 ms
10,824 KB
testcase_35 AC 91 ms
9,876 KB
testcase_36 AC 89 ms
9,836 KB
testcase_37 AC 63 ms
8,636 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 44 ms
11,720 KB
testcase_44 AC 33 ms
8,888 KB
testcase_45 AC 43 ms
11,532 KB
testcase_46 AC 2 ms
5,992 KB
testcase_47 AC 3 ms
5,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1364.cc:  No.1364 [Renaming] Road to Cherry from Zelkova - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000 + 1;
const int MAX_M = 200000;
const int MOD = 1000000007;

/* typedef */

typedef long long ll;
typedef queue<int> qi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

/* global variables */

int ls[MAX_M], as[MAX_M];
vpii nbrs[MAX_N];
int ps[MAX_N], cis[MAX_N], pns[MAX_N];
bool used[MAX_N], pts[MAX_N], lps[MAX_N], lpes[MAX_M];
int ds[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d%d%d", &u, &v, ls + i, as + i);
    nbrs[u].push_back(pii(v, i));
  }

  ps[0] = -1;
  used[0] = true;
  for (int u = 0; u >= 0;) {
    vpii &nbru = nbrs[u];
    if (cis[u] == 0) pts[u] = true;
    if (cis[u] < nbru.size()) {
      pii pv = nbru[cis[u]++];
      int v = pv.first, ei = pv.second;

      if (pts[v]) lps[v] = lpes[ei] = true;
      else {
	pns[v]++;
	if (! used[v]) {
	  ps[v] = u;
	  used[v] = true;
	  u = v;
	}
      }
    }
    else {
      pts[u] = false;
      u = ps[u];
    }
  }
  //for (int i = 0; i <= n; i++) printf("%d", lps[i]); putchar('\n');

  ds[0] = 0;
  qi q;
  q.push(0);

  while (! q.empty()) {
    int u = q.front(); q.pop();
    if (u == n) break;

    vpii &nbru = nbrs[u];
    for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int v = vit->first, ei = vit->second;
      if (! lpes[ei]) {
	lps[v] = (lps[v] || lps[u]);
	ds[v] = (ds[v] + (ll)(ds[u] + ls[ei]) % MOD * as[ei] % MOD) % MOD;
	if (--pns[v] == 0) q.push(v);
      }
    }
  }
  //for (int i = 0; i <= n; i++) printf("%d", lps[i]); putchar('\n');

  if (lps[n]) puts("INF");
  else printf("%d\n", ds[n]);
  return 0;
}
0