結果
| 問題 |
No.3319 Iwaijkstra
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-31 23:56:32 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,709 bytes |
| コンパイル時間 | 5,018 ms |
| コンパイル使用メモリ | 276,620 KB |
| 実行使用メモリ | 22,328 KB |
| 最終ジャッジ日時 | 2025-10-31 23:56:53 |
| 合計ジャッジ時間 | 16,083 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 3 |
| other | RE * 12 TLE * 1 -- * 45 |
ソースコード
#include "atcoder/scc.hpp"
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using i32 = int;
using i64 = long long;
using i128 = __int128_t;
using p2 = pair<i64, i64>;
using el = tuple<i64, i64, i64>;
using f64 = long double;
using mint = atcoder::modint998244353;
void _main();
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(18);
_main();
}
i64 pow(i64 a, i64 n) {
i64 res = 1;
i64 x = a;
while (n > 0) {
if (n & 1) res *= x;
x *= x;
n >>= 1;
}
return res;
}
p2 op(p2 a, p2 b) {return min(a, b);}
p2 e() {return {1e18, 1e18};}
p2 mpn(i64 f, p2 x) {return x.second == -1 ? x : (p2){min(f, x.first), x.second};}
i64 cmp(i64 f, i64 g) {return min(f, g);}
i64 idn() {return 1e18;}
p2 opx(p2 a, p2 b) {return max(a, b);}
p2 ex() {return {0, -1};}
bool dfs(i64 v, vector<vector<el>> &g, atcoder::segtree<p2, opx, ex> &seg0, atcoder::segtree<p2, opx, ex> &seg1) {
seg0.set(v, {0, v});
for (auto [l, r, c] : g[v]) {
if (c != 0) continue;
while (seg1.prod(l, r).first == 1) {
auto [_, nv] = seg1.prod(l, r);
if (seg0.get(nv).first == 0) return true;
bool res = dfs(nv, g, seg0, seg1);
if (res) return true;
}
}
seg1.set(v, {0, v});
return false;
}
void _main() {
i64 n, m;
cin >> n >> m;
vector<tuple<i64, i64, i64, i64>> edge(m);
vector<vector<el>> g(n);
for (i64 i = 0; i < m; i++) {
i64 x, l, r, c;
cin >> x >> l >> r >> c;
x--;
l--;
edge[i] = {x, l, r, c};
g[x].push_back({l, r, c});
}
vector<i64> dist(n, 1e18);
{
atcoder::lazy_segtree<p2, op, e, i64, mpn, cmp, idn> seg(n);
for (i64 i = 0; i < n; i++) seg.set(i, {1e18, i});
seg.set(0, {0, 0});
while (seg.all_prod().first != 1e18) {
auto [d, i] = seg.all_prod();
seg.set(i, {1e18, -1});
dist[i] = d;
for (auto [l, r, c] : g[i]) {
seg.apply(l, r, d + c);
}
}
}
for (i64 i = 0; i < n; i++) {
if (dist[i] == 1e18) continue;
for (auto [l, r, c] : g[i]) {
if (c == 0 && l <= i && i < r) {
cout << "Too Many\n";
return;
}
}
}
{
atcoder::segtree<p2, opx, ex> seg0(n), seg1(n);
for (i64 i = 0; i < n; i++) {
seg0.set(i, {1, i});
seg1.set(i, {1, i});
}
bool f = dfs(0, g, seg0, seg1);
if (f) {
cout << "Too Many\n";
return;
}
}
vector<i64> ord(n);
for (i64 i = 0; i < n; i++) {
ord[i] = i;
}
sort(ord.begin(), ord.end(), [&](i64 a, i64 b){
if (dist[a] < dist[b]) return a;
if (dist[b] < dist[a]) return b;
for (auto [l, r, x] : g[a]) {
if (x == 0 && l <= b && b < r) return a;
}
return b;
});
}