結果
| 問題 | No.2477 Drifting |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-06-21 15:38:34 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,862 bytes |
| コンパイル時間 | 1,274 ms |
| コンパイル使用メモリ | 79,472 KB |
| 最終ジャッジ日時 | 2025-02-21 23:40:57 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 6 TLE * 1 -- * 7 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:45:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
45 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:49:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
49 | scanf("%d%d%d", &u, &v, &w);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:55:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
55 | scanf("%d", &k);
| ~~~~~^~~~~~~~~~
main.cpp:59:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
59 | scanf("%d%d%d", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 2477.cc: No.2477 Drifting - yukicoder
*/
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;
/* constant */
const int MAX_N = 200000;
const int MAX_M = 200000;
const int MAX_GN = MAX_N + MAX_M;
const long long LINF = 1LL << 62;
/* typedef */
using ll = long long;
using vl = vector<ll>;
using pii = pair<int,int>;
using vpii = vector<pii>;
using si = set<int>;
using vsi = vector<si>;
using mii = map<int,int>;
/* global variables */
vpii nbrs[MAX_N];
mii exis[MAX_N];
vsi excs[MAX_N];
vl dp[MAX_N];
/* subroutines */
/* main */
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
u--, v--;
nbrs[u].push_back({v, w});
}
int k;
scanf("%d", &k);
for (int i = 0; i < k; i++) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
a--, b--, c--;
auto mit = exis[b].find(a);
int j = 0;
if (mit != exis[b].end()) j = mit->second;
else j = exis[b][a] = exis[b].size();
if (j < excs[b].size()) excs[b][j].insert(c);
else {
si cs; cs.insert(c);
excs[b].push_back(cs);
}
}
for (int u = 0; u < n; u++) {
excs[u].push_back(si());
dp[u].assign((int)excs[u].size(), LINF);
}
dp[0][0] = 0;
for (int u = 0; u < n; u++)
for (int i = 0; i < excs[u].size(); i++)
if (dp[u][i] < LINF) {
for (auto [v, w]: nbrs[u]) {
if (! excs[u][i].empty() &&
excs[u][i].find(v) != excs[u][i].end())
continue;
auto mit = exis[v].find(u);
int j =
(mit != exis[v].end()) ? mit->second : exis[v].size();
dp[v][j] = min(dp[v][j], dp[u][i] + w);
}
}
ll mind = *min_element(dp[n - 1].begin(), dp[n - 1].end());
printf("%lld\n", (mind < LINF) ? mind : -1LL);
return 0;
}
tnakao0123