結果
問題 |
No.468 役に立つ競技プログラミング実践編
|
ユーザー |
|
提出日時 | 2016-12-18 08:41:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,998 bytes |
コンパイル時間 | 1,002 ms |
コンパイル使用メモリ | 89,400 KB |
実行使用メモリ | 36,604 KB |
最終ジャッジ日時 | 2024-12-14 07:51:42 |
合計ジャッジ時間 | 10,922 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 23 WA * 8 |
other | AC * 6 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <tuple> #include <map> using namespace std; typedef tuple<int, int> itup; typedef map<itup, int> cmap; typedef vector<int> ivec; cmap cost; ivec r[100000], s[100000], buf1(100000), buf2(100000), *tmp1 = &buf1, *tmp2 = &buf2, *tmp3; unsigned t1[100000], c1[100000], t2[100000], c2[100000]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; r[a].push_back(b); s[b].push_back(a); cost[{a, b}] = c; } for (int i = 0; i < n; i++) c2[i] = 16000000; tmp1->push_back(0); while (tmp1->size()) { tmp2->clear(); for (auto it=tmp1->begin();it!=tmp1->end();it++) { auto a=*it; auto ca=c1[a]; auto hnd=&r[a]; for (auto bp=hnd->begin();bp!=hnd->end();bp++) { auto b=*bp; c1[b] = max(c1[b], ca + cost[{a,b}]); t1[b]++; if (t1[b] == s[b].size()) tmp2->push_back(b); } } tmp3=tmp1;tmp1=tmp2;tmp2=tmp3; } c2[n - 1] = c1[n - 1]; tmp1->clear(); tmp1->push_back(n - 1); while (tmp1->size()) { tmp2->clear(); for (auto it=tmp1->begin();it!=tmp1->end();it++) { auto b=*it; auto cb=c2[b]; auto hnd=&s[b]; for (auto ap=hnd->begin();ap!=hnd->end();ap++) { auto a=*ap; c2[a] = min(c2[a], cb - cost[{a,b}]); t2[a]++; if (t2[a] == r[a].size()) tmp2->push_back(a); } } tmp3=tmp1;tmp1=tmp2;tmp2=tmp3; } int p = 0; for (int i = 0; i < n; i++) { if (c1[i] != c2[i]) p++; } cout << c1[n - 1] << ' ' << p << '/' << n << endl; // for(int i = 0; i < n; i++)cout << i << ':' << c1[i] << ',' << c2[i] << endl; return 0; }