QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#139455 | #6523. Escape Plan | UrgantTeam# | AC ✓ | 1133ms | 60440kb | C++23 | 2.4kb | 2023-08-13 16:25:59 | 2023-08-13 16:26:03 |
Judging History
answer
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second
using namespace std;
typedef long double ld;
typedef long long ll;
const int INF = (int) 2e9;
struct triple
{
int u, weight, num;
};
vector <triple> g[100005];
int monster[100005], dist[100005];
bool is_exit[100005];
set <pair <int, int> > sosed[100005];
set <pair <int, int> > cand;
int value[100005];
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(0);
int test;
cin >> test;
for (int rep = 1; rep <= test; rep++)
{
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) g[i].clear(), is_exit[i] = false, sosed[i].clear(), value[i] = 0;
cand.clear();
for (int i = 1; i <= k; i++)
{
int ex;
cin >> ex;
is_exit[ex] = true;
}
for (int i = 1; i <= n; i++) cin >> monster[i];
for (int i = 1; i <= m; i++)
{
int u, v, w;
cin >> u >> v >> w;
g[u].pb({v, w, i});
g[v].pb({u, w, i});
}
for (int i = 1; i <= n; i++)
{
if (!is_exit[i]) dist[i] = INF;
else dist[i] = 0;
}
for (int i = 1; i <= n; i++)
{
if (dist[i] != INF) continue;
for (const auto &[u, w, num] : g[i])
if (dist[u] != INF)
{
sosed[i].insert(mp(dist[u] + w, num));
if ((int) sosed[i].size() > monster[i] + 1) sosed[i].erase(*sosed[i].rbegin());
if ((int) sosed[i].size() == monster[i] + 1)
{
cand.erase(mp(value[i], i));
value[i] = (*sosed[i].rbegin()).x;
cand.insert(mp(value[i], i));
}
}
}
while (!cand.empty())
{
pair <int, int> A = *cand.begin();
cand.erase(cand.begin());
int len = A.x, v = A.y;
dist[v] = len;
for (const auto &[u, w, num] : g[v])
{
if (dist[u] != INF) continue;
sosed[u].insert(mp(dist[v] + w, num));
if ((int) sosed[u].size() > monster[u] + 1) sosed[u].erase(*sosed[u].rbegin());
if ((int) sosed[u].size() == monster[u] + 1)
{
cand.erase(mp(value[u], u));
value[u] = (*sosed[u].rbegin()).x;
cand.insert(mp(value[u], u));
}
}
}
if (dist[1] == INF) cout << "-1\n";
else cout << dist[1] << '\n';
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 11352kb
input:
2 3 4 1 3 1 1 1 1 2 1 1 2 2 2 3 1 2 3 2 3 2 2 2 3 2 0 0 1 2 1 1 3 1
output:
4 -1
result:
ok 2 number(s): "4 -1"
Test #2:
score: 0
Accepted
time: 1133ms
memory: 60440kb
input:
100 100 1808 2 94 47 3 3 0 2 4 3 3 4 0 0 2 2 2 3 2 4 0 2 3 4 4 2 0 3 4 3 1 0 2 1 2 2 0 3 4 4 4 1 2 2 3 1 0 0 3 1 4 2 1 3 3 4 3 0 4 1 0 3 2 1 4 4 1 3 2 3 3 3 3 1 0 3 0 4 3 1 0 4 0 4 4 1 2 0 0 4 1 3 3 3 0 2 2 1 1 2 3 4 1 2 72 29 1138 59 78 2398 95 5 1610 32 46 4176 36 99 8143 100 69 413 61 58 1595 9 9...
output:
5109 1021 3293 4646 3796 3394 1884 6772 2329 2067 3296 2809 865 4249 2241 3792 2135 2544 3343 1775 10602 4677 1700 2150 7071 14055 3368 2322 1113 1980 3067 1617 1702 -1 2879 6265 2065 2810 2289 3001 402 3769 18118 6874 7879 3823 -1 510 2636 10564 -1 3166 3615 7526 5549 1261 3302 270 4440 1998 3350 3...
result:
ok 100 numbers