QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#537485 | #7883. Takeout Delivering | MaxDYF | WA | 218ms | 57932kb | C++23 | 3.2kb | 2024-08-30 14:17:33 | 2024-08-30 14:17:33 |
Judging History
answer
// #pragma GCC optimize("Ofast,no-stack-protector")
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const int inf = 1 << 30;
const long long llinf = 1ll << 60;
const double PI = acos(-1);
#define lowbit(x) (x & -x)
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<db, db> pdd;
typedef pair<ll, int> pli;
int n, m, k, q;
namespace Graph1
{
typedef int64_t T;
typedef std::pair<int64_t, int32_t> pli;
std::vector<pli> to[N];
void add(int x, int y, T val)
{
to[x].push_back({val, y});
}
bool vis[N];
T dis[N];
void shortest_path(int32_t from)
{
// using Dijkstra
std::priority_queue<pli, std::vector<pli>, std::greater<pli>> q;
q.push(std::make_pair(0, from));
memset(dis, 0x3f, sizeof dis);
memset(vis, 0, sizeof vis);
dis[from] = 0;
while (!q.empty())
{
auto [nowval, x] = q.top();
q.pop();
if (vis[x])
continue;
vis[x] = 1;
for (auto [val, y] : to[x])
if (dis[y] > dis[x] + val)
{
dis[y] = dis[x] + val;
q.push(std::make_pair(dis[y], y));
}
}
}
}
namespace Graph2
{
typedef int64_t T;
typedef std::pair<int64_t, int32_t> pli;
std::vector<pli> to[N];
void add(int x, int y, T val)
{
to[x].push_back({val, y});
}
bool vis[N];
T dis[N];
void shortest_path(int32_t from)
{
// using Dijkstra
std::priority_queue<pli, std::vector<pli>, std::greater<pli>> q;
q.push(std::make_pair(0, from));
memset(dis, 0x3f, sizeof dis);
memset(vis, 0, sizeof vis);
dis[from] = 0;
while (!q.empty())
{
auto [nowval, x] = q.top();
q.pop();
if (vis[x])
continue;
vis[x] = 1;
for (auto [val, y] : to[x])
if (dis[y] > max(dis[x], val))
{
dis[y] = max(dis[x], val);
q.push(std::make_pair(dis[y], y));
}
}
}
}
void work()
{
cin >> n >> m;
struct Edge
{
int x, y, w;
bool operator<(Edge b)
{
return w < b.w;
}
};
vector<Edge> vec;
for (int i = 0; i < m; i++)
{
int x, y, v;
cin >> x >> y >> v;
Graph1::add(x, y, v);
Graph1::add(y, x, v);
Graph2::add(x, y, v);
Graph2::add(y, x, v);
vec.push_back(Edge{x, y, v});
}
Graph1::shortest_path(1);
Graph2::shortest_path(n);
int ans = 2e9;
for (auto [x, y, w] : vec)
{
int max1 = max(Graph1::dis[x], Graph2::dis[y]);
int max2 = max(Graph2::dis[x], Graph1::dis[y]);
if (max1 <= w || max2 <= w)
ans = min(ans, min(max1, max2) + w);
}
cout << ans << endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t-- > 0)
{
work();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 10020kb
input:
4 6 1 2 2 1 3 4 1 4 7 2 3 1 2 4 3 3 4 9
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: -100
Wrong Answer
time: 218ms
memory: 57932kb
input:
300000 299999 80516 80517 597830404 110190 110191 82173886 218008 218009 954561262 250110 250111 942489774 66540 66541 156425292 34947 34948 239499776 273789 273790 453201232 84428 84429 439418398 98599 98600 326095035 55636 55637 355015760 158611 158612 684292473 43331 43332 43265001 171621 171622 ...
output:
-2143974584
result:
wrong answer 1st numbers differ - expected: '1999991697', found: '-2143974584'