結果
| 問題 |
No.468 役に立つ競技プログラミング実践編
|
| ユーザー |
|
| 提出日時 | 2016-12-18 09:05:22 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,149 bytes |
| コンパイル時間 | 1,072 ms |
| コンパイル使用メモリ | 77,244 KB |
| 実行使用メモリ | 56,288 KB |
| 最終ジャッジ日時 | 2024-12-14 07:52:40 |
| 合計ジャッジ時間 | 13,424 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / 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<long long, long long> cmap;
typedef vector<int> ivec;
cmap cost;
ivec r[100000], s[100000], buf1(100000), buf2(100000), *tmp1 = &buf1, *tmp2 = &buf2, *tmp3;
unsigned t1[100000], t2[100000];
long long c1[100000], c2[100000];
inline
long long ky(const int a, const int b) { return 100000LL*(long long)a + (long long)b; }
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[ky(a,b)] = c;
cost[ky(b,a)] = c;
}
for (int i = 0; i < n; i++) c2[i] = 16000000LL;
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[ky(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[ky(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;
}