結果
問題 | No.654 Air E869120 |
ユーザー | sirogamichan1 |
提出日時 | 2021-03-05 14:31:25 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 6,053 bytes |
コンパイル時間 | 6,527 ms |
コンパイル使用メモリ | 380,824 KB |
実行使用メモリ | 66,096 KB |
最終ジャッジ日時 | 2024-10-06 13:06:40 |
合計ジャッジ時間 | 8,069 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 7 ms
5,248 KB |
testcase_11 | AC | 8 ms
5,248 KB |
testcase_12 | AC | 7 ms
5,248 KB |
testcase_13 | AC | 8 ms
5,248 KB |
testcase_14 | AC | 7 ms
5,248 KB |
testcase_15 | AC | 7 ms
5,248 KB |
testcase_16 | AC | 10 ms
5,248 KB |
testcase_17 | AC | 12 ms
5,248 KB |
testcase_18 | AC | 10 ms
5,248 KB |
testcase_19 | AC | 11 ms
5,248 KB |
testcase_20 | AC | 6 ms
5,248 KB |
testcase_21 | AC | 7 ms
5,248 KB |
testcase_22 | AC | 5 ms
5,248 KB |
testcase_23 | AC | 5 ms
5,248 KB |
testcase_24 | AC | 6 ms
5,248 KB |
testcase_25 | AC | 5 ms
5,248 KB |
testcase_26 | AC | 5 ms
5,248 KB |
testcase_27 | AC | 6 ms
6,016 KB |
testcase_28 | AC | 6 ms
6,144 KB |
testcase_29 | AC | 6 ms
6,272 KB |
testcase_30 | AC | 29 ms
66,012 KB |
testcase_31 | AC | 30 ms
66,096 KB |
testcase_32 | AC | 30 ms
65,920 KB |
testcase_33 | AC | 30 ms
66,048 KB |
testcase_34 | AC | 29 ms
65,920 KB |
testcase_35 | AC | 2 ms
5,248 KB |
testcase_36 | AC | 1 ms
5,248 KB |
testcase_37 | AC | 2 ms
5,248 KB |
testcase_38 | AC | 1 ms
5,248 KB |
testcase_39 | AC | 2 ms
5,248 KB |
ソースコード
////////////////////////////// // Check before you submit. // #define _ATCODER_LIBRARY const long long MOD = 1e9+7; // const long long MOD = 998244353; ///////////////////////////// #include <bits/stdc++.h> using namespace std; #include <boost/multiprecision/cpp_int.hpp> using namespace boost::multiprecision; #ifdef _ATCODER_LIBRARY #include <atcoder/all> using namespace atcoder; #endif // _ATCODER_LIBRARY const long long INF = 1LL << 60; const double PI = acos(-1); using ll = long long; using P = array<ll, 2>; #define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() #define SUM(v) accumulate(ALL(v),0ll) template<typename T>istream& operator>>(istream&i,vector<T>&v){REP(j,v.size())i>>v[j];return i;} template<typename T>string join(vector<T>&v){stringstream s;REP(i,v.size())s<<' '<<v[i];return s.str().substr(1);} template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;} template<typename T>string join(vector<vector<T>>&vv){string s="\n";REP(i,vv.size())s+=join(vv[i])+"\n";return s;} template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;} template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;} template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v){return o<<"("<<v.first<<","<<v.second<<")";} template<typename T>istream& operator>>(istream&i,array<T,2>&v){i>>v[0]>>v[1]; return i;} template<typename T>ostream& operator<<(ostream&o,array<T,2>&v){return o<<"("<<v[0]<<","<<v[1]<<")"; return o;} #define DEBUG(x); #ifdef _DEBUG #define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl; #define GLIBCXX_DEBUG #define GLIBCXX_DEBUG_PEDANTIC #endif // _DEBUG int dx[4]{0, 1, 0, -1}; int dy[4]{1, 0, -1, 0}; void init_init_init() {ios_base::sync_with_stdio(false);cin.tie(NULL);std::cout<<fixed<<setprecision(10);} template<class T>T up(T a, T b){assert(b);return (a+b-1)/b;} template<typename... A>bool eq(A const&... a){auto t={a...};assert(t.size());auto tar=*t.begin();for(const auto&e:t)if(tar!=e)return false;return true;} template<class T>bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;} template<class T>bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;} template<class T>bool chmax(T &a, initializer_list<T>l){return chmax(a,max(l));} template<class T>bool chmin(T &a, initializer_list<T>l){return chmin(a,min(l));} ////////////////////////////////////////////////////////////////// // My Library ////////////////////////////////////////////////////////////////// template<typename T> class Dinic { private: int V; vector<int> level,iter; void bfs(int s) { fill(level.begin(),level.end(),-1); queue<int> que; level[s] = 0; 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){ level[e.to] = level[v] + 1; que.push(e.to); } } } } T dfs(int v,int t,T f) { if(v==t){ return f; } for(int& i = iter[v]; i < (int)G[v].size(); i++){ edge& e = G[v][i]; if(e.cap > 0 && level[v] < level[e.to]){ T d = dfs(e.to,t,min(f,e.cap)); if(d > 0){ e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; } public: struct edge{ int to; T cap; int rev; }; vector<vector<edge> > G; Dinic(int node_size) : V(node_size), level(V), iter(V), G(V){} // Adding edge on a node. void add_edge(int from,int to,T cap) { G[from].push_back((edge){to,cap,(int)G[to].size()}); G[to].push_back((edge){from,(T)0,(int)G[from].size()-1}); } // Calculate the maximum flow. T solve(int s,int t) { T flow = 0; for(;;){ bfs(s); if(level[t] < 0) return flow; fill(iter.begin(),iter.end(),0); T f; while((f=dfs(s,t,numeric_limits<T>::max())) > 0){ flow += f; } } } }; template< typename T > struct Compress { vector< T > xs; Compress() = default; Compress(const vector< T > &vs) { add(vs); } Compress(const initializer_list< vector< T > > &vs) { for(auto &p : vs) add(p); } void add(const vector< T > &vs) { copy(begin(vs), end(vs), back_inserter(xs)); } void add(const T &x) { xs.emplace_back(x); } void build() { sort(begin(xs), end(xs)); xs.erase(unique(begin(xs), end(xs)), end(xs)); } int size() { return (int)xs.size(); } vector< int > get(const vector< T > &vs) const { vector< int > ret; transform(begin(vs), end(vs), back_inserter(ret), [&](const T &x) { return lower_bound(begin(xs), end(xs), x) - begin(xs); }); return ret; } int get(const T &x) const { return lower_bound(begin(xs), end(xs), x) - begin(xs); } const T &operator[](int k) const { return xs[k]; } }; ////////////////////////////////////////////////////////////////// // Contest Code ////////////////////////////////////////////////////////////////// int main(int argc, char **argv) { init_init_init(); ll N, M, d; cin >> N >> M >> d; using T = tuple<ll, ll, ll, ll, ll>; vector<vector<ll>> uni_pre(N); vector<T> info; REP(i, M) { ll u, v, p, q, w; cin >> u>>v>>p>>q>>w; --u, --v; if (v != N-1) q += d; info.push_back({u, v, p, q, w}); uni_pre[u].push_back(p); uni_pre[v].push_back(q); } vector<Compress<ll>> comp(N); REP(i, N) { comp[i] = Compress<ll>(uni_pre[i]); comp[i].build(); } Dinic<ll> max_flow(N*M*2); vector<ll> add_constant(N); set<ll> se; ll sz{0}; // infの変をはる REP(i, N) { add_constant[i] = sz; for (ll j = sz; j < sz+comp[i].size()-1; ++j) { DEBUG(j); max_flow.add_edge(j, j+1, INF); } DEBUG(comp[i].size()); DEBUG("----"); sz += comp[i].size(); } REP(i, M) { auto [u, v, p, q, w] = info[i]; ll id_p = comp[u].get(p) + add_constant[u]; ll id_q = comp[v].get(q) + add_constant[v]; max_flow.add_edge(id_p, id_q, w); } std::cout << max_flow.solve(0, sz-1) << std::endl; }