結果
| 問題 |
No.654 Air E869120
|
| コンテスト | |
| ユーザー |
YZYZ_
|
| 提出日時 | 2025-06-27 11:52:07 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 9,085 bytes |
| コンパイル時間 | 4,309 ms |
| コンパイル使用メモリ | 307,224 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-06-27 11:52:14 |
| 合計ジャッジ時間 | 5,344 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 WA * 1 |
| other | AC * 11 WA * 24 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.hpp"
#else
#define de(...) ((void)0)
#define dl(...) ((void)0)
#endif
using ll = long long;
using ull = unsigned long long;
using i128 = __int128_t;
using P = pair<ll, ll>;
const ll INF = 1LL << 60;
const int inf = 1073741823;
#define endl '\n'
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, m, n) for (int i = (m); i < (n); ++i)
#define per(i, n) for (int i = (n) - 1; i >= 0; --i)
#define fore(x, a) for (auto &x : (a))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
template <typename T>
void read_single(T &x) {
cin >> x;
}
template <typename T, typename... Ts>
void read_single(T &x, Ts &...xs) {
cin >> x;
read_single(xs...);
}
#define INT(...) \
int __VA_ARGS__; \
read_single(__VA_ARGS__)
#define LL(...) \
long long __VA_ARGS__; \
read_single(__VA_ARGS__)
template <typename T>
void write_single(const T &x) {
cout << x;
}
void write_single(const vector<string>& v) {
for (size_t i = 0; i < v.size(); ++i) {
if (i) cout << '\n';
cout << v[i];
}
}
template <typename T>
void write_single(const vector<T> &v) {
for (size_t i = 0; i < v.size(); ++i) {
if (i) cout << ' ';
write_single(v[i]);
}
}
template <typename T, typename U>
void write_single(const pair<T, U> &p) {
write_single(p.first);
cout << ' ';
write_single(p.second);
}
template <typename T, typename... Ts>
void write_single(const T &x, const Ts &...xs) {
cout << x;
if (sizeof...(xs)) {
cout << ' ';
write_single(xs...);
}
}
template <typename T>
void write_single(const vector<vector<T>> &m) {
for (size_t i = 0; i < m.size(); ++i) {
write_single(m[i]);
cout << '\n';
}
}
#define print(...) \
do { \
write_single(__VA_ARGS__); \
cout << '\n'; \
} while (0)
#define yesno(cond) PRINT((cond) ? "Yes" : "No")
template <class T>
inline int popcount(T x) {
return __builtin_popcountll((ull)x);
}
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vector<T>>;
template <class T>
using maxPQ = priority_queue<T>;
template <class T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;
template <class T>
T div_floor(T a, T b) {
if (b < 0) a = -a, b = -b;
return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
if (b < 0) a = -a, b = -b;
return a > 0 ? (a - 1) / b + 1 : a / b;
}
template <class T>
inline bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T, typename U>
T SUM(const vector<U> &A) {
T sm = 0;
for (auto &&a : A) sm += a;
return sm;
}
template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
int n = A.size();
vector<T> B(n + 1);
rep(i, n) { B[i + 1] = B[i] + A[i]; }
if (off == 0) B.erase(B.begin());
return B;
}
template <typename T>
T ipow(T a, long long b) {
T res = 1;
while (b > 0) {
if (b & 1) res *= a;
a *= a;
b >>= 1;
}
return res;
}
#include <algorithm>
#include <cassert>
#include <limits>
#include <queue>
#include <vector>
#include <vector>
namespace atcoder {
namespace internal {
template <class T> struct simple_queue {
std::vector<T> payload;
int pos = 0;
void reserve(int n) { payload.reserve(n); }
int size() const { return int(payload.size()) - pos; }
bool empty() const { return pos == int(payload.size()); }
void push(const T& t) { payload.push_back(t); }
T& front() { return payload[pos]; }
void clear() {
payload.clear();
pos = 0;
}
void pop() { pos++; }
};
} // namespace internal
} // namespace atcoder
namespace atcoder {
template <class Cap> struct mf_graph {
public:
mf_graph() : _n(0) {}
explicit mf_graph(int n) : _n(n), g(n) {}
int add_edge(int from, int to, Cap cap) {
assert(0 <= from && from < _n);
assert(0 <= to && to < _n);
assert(0 <= cap);
int m = int(pos.size());
pos.push_back({from, int(g[from].size())});
int from_id = int(g[from].size());
int to_id = int(g[to].size());
if (from == to) to_id++;
g[from].push_back(_edge{to, to_id, cap});
g[to].push_back(_edge{from, from_id, 0});
return m;
}
struct edge {
int from, to;
Cap cap, flow;
};
edge get_edge(int i) {
int m = int(pos.size());
assert(0 <= i && i < m);
auto _e = g[pos[i].first][pos[i].second];
auto _re = g[_e.to][_e.rev];
return edge{pos[i].first, _e.to, _e.cap + _re.cap, _re.cap};
}
std::vector<edge> edges() {
int m = int(pos.size());
std::vector<edge> result;
for (int i = 0; i < m; i++) {
result.push_back(get_edge(i));
}
return result;
}
void change_edge(int i, Cap new_cap, Cap new_flow) {
int m = int(pos.size());
assert(0 <= i && i < m);
assert(0 <= new_flow && new_flow <= new_cap);
auto& _e = g[pos[i].first][pos[i].second];
auto& _re = g[_e.to][_e.rev];
_e.cap = new_cap - new_flow;
_re.cap = new_flow;
}
Cap flow(int s, int t) {
return flow(s, t, std::numeric_limits<Cap>::max());
}
Cap flow(int s, int t, Cap flow_limit) {
assert(0 <= s && s < _n);
assert(0 <= t && t < _n);
assert(s != t);
std::vector<int> level(_n), iter(_n);
internal::simple_queue<int> que;
auto bfs = [&]() {
std::fill(level.begin(), level.end(), -1);
level[s] = 0;
que.clear();
que.push(s);
while (!que.empty()) {
int v = que.front();
que.pop();
for (auto e : g[v]) {
if (e.cap == 0 || level[e.to] >= 0) continue;
level[e.to] = level[v] + 1;
if (e.to == t) return;
que.push(e.to);
}
}
};
auto dfs = [&](auto self, int v, Cap up) {
if (v == s) return up;
Cap res = 0;
int level_v = level[v];
for (int& i = iter[v]; i < int(g[v].size()); i++) {
_edge& e = g[v][i];
if (level_v <= level[e.to] || g[e.to][e.rev].cap == 0) continue;
Cap d =
self(self, e.to, std::min(up - res, g[e.to][e.rev].cap));
if (d <= 0) continue;
g[v][i].cap += d;
g[e.to][e.rev].cap -= d;
res += d;
if (res == up) return res;
}
level[v] = _n;
return res;
};
Cap flow = 0;
while (flow < flow_limit) {
bfs();
if (level[t] == -1) break;
std::fill(iter.begin(), iter.end(), 0);
Cap f = dfs(dfs, t, flow_limit - flow);
if (!f) break;
flow += f;
}
return flow;
}
std::vector<bool> min_cut(int s) {
std::vector<bool> visited(_n);
internal::simple_queue<int> que;
que.push(s);
while (!que.empty()) {
int p = que.front();
que.pop();
visited[p] = true;
for (auto e : g[p]) {
if (e.cap && !visited[e.to]) {
visited[e.to] = true;
que.push(e.to);
}
}
}
return visited;
}
private:
int _n;
struct _edge {
int to, rev;
Cap cap;
};
std::vector<std::pair<int, int>> pos;
std::vector<std::vector<_edge>> g;
};
} // namespace atcoder
using namespace atcoder;
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
LL(n,m,d);
vec<ll> uu(m),vv(m),pp(m),qq(m),ww(m);
map<P,int> id;
int cnt=0;
rep(i,m){
cin>>uu[i]>>vv[i]>>pp[i]>>qq[i]>>ww[i];
if(!id.contains({uu[i],pp[i]})){
id[{uu[i],pp[i]}]=cnt;
cnt++;
}
if(!id.contains({vv[i],qq[i]})){
id[{vv[i],qq[i]}]=cnt;
cnt++;
}
}
mf_graph<ll> mf(cnt+2);
vvec<P> t(n);
rep(i,m){
ll u=uu[i],w=ww[i],v=vv[i],p=pp[i],q=qq[i];
t[u-1].eb(p,id[{u,p}]);
t[v-1].eb(q,id[{v,q}]);
mf.add_edge(id[{u,p}],id[{v,q}],w);
if(u==1)mf.add_edge(cnt,id[{u,p}],INF);
if(v==n)mf.add_edge(id[{v,q}],cnt+1,INF);
}
rep(i,n){
sort(all(t[i]));
rep(j,ssize(t[i])-1){
if(t[i][j+1].first-t[i][j].first>=d)
mf.add_edge(t[i][j].second,t[i][j+1].second,INF);
}
}
ll ans=mf.flow(cnt,cnt+1);
print(ans);
return 0;
}
YZYZ_