QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#522695 | #7048. Delivery Route | QFshengxiu | WA | 14ms | 5700kb | C++20 | 3.4kb | 2024-08-17 11:28:49 | 2024-08-17 11:28:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define lowbit(x) (x & (-x))
#define all(x) x.begin(), x.end()
// #define int long long
#define pai 3.14
#define QF ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define c1 cout << 1
#define c2 cout << 2
// #define width cout << ""
// using ll = long long;
using PII = pair<int, int>;
// using LD = long double;
const int inf = 1e9;
// mt19937_64 rnd(chrono::duration_cast<chrono::nanoseconds>(chrono::system_clock::now().time_since_epoch()).count());
constexpr int N = 3e4 + 10;
int n, x, y, s, tot, dn;
int vis[N], fa[N], ru[N], tps[N];
int dis[N];
vector<PII> g[N], e[N], nxt[N];
vector<int> scc[N];
int find(int x)
{
if (fa[x] != x)
return fa[x] = find(fa[x]);
return x;
}
void uniun(int u, int v)
{
int fu = find(u);
int fv = find(v);
if (fu == fv)
return;
fa[fu] = fv;
}
void tuopu()
{
vector<int> sse;
for (int i = 1; i <= n; i++)
{
if (!ru[fa[i]])
sse.push_back(fa[i]);
}
sse.erase(unique(sse.begin(), sse.end()), sse.end());
queue<int> t;
for (auto v : sse)
{
t.push(v);
}
while (!t.empty())
{
auto p = t.front();
t.pop();
tps[++tot] = p;
for (auto u : scc[p])
{
for (auto [v, w] : g[u])
{
ru[fa[v]]--;
if (!ru[fa[v]])
t.push(fa[v]);
}
}
}
}
void dij(int rt)
{
priority_queue<PII> q;
for (auto u : scc[rt])
{
if (dis[u] != inf)
q.push({dis[u], u});
}
while (!q.empty())
{
auto [w, u] = q.top();
q.pop();
if (dis[u] != w)
continue;
for (auto [v, ww] : e[u])
{
if (dis[v] > dis[u] + ww)
{
dis[v] = dis[u] + ww;
q.push({dis[v], v});
}
}
}
}
void solve()
{
cin >> n >> x >> y >> s;
for (int i = 1; i <= n; i++)
{
fa[i] = i;
dis[i] = inf;
}
for (int i = 1; i <= x; i++)
{
int u, v, w;
cin >> u >> v >> w;
e[u].push_back({v, w});
e[v].push_back({u, w});
uniun(u, v);
}
for (int i = 1; i <= n; i++)
{
fa[i] = find(i);
}
for (int i = 1; i <= y; i++)
{
int u, v, w;
cin >> u >> v >> w;
g[u].push_back({v, w});
ru[fa[v]]++;
}
for (int i = 1; i <= n; i++)
{
// cout << find(i) << endl;
scc[fa[i]].push_back(i);
}
tuopu();
dis[s] = 0;
for (int i = 1; i <= tot; i++)
{
auto p = tps[i];
dij(p);
for (auto u : scc[p])
{
if (dis[u] == inf)
continue;
for (auto [v, w] : g[u])
{
dis[v] = min(dis[v], dis[u] + w);
}
}
}
for (int i = 1; i <= n; i++)
{
if (dis[i] == inf)
cout << "NO PATH" << endl;
else
cout << dis[i] << endl;
}
}
signed main()
{
QF;
int T = 1;
// cin >> T;
for (int i = 1; i <= T; i++)
{
solve();
// cout << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3640kb
input:
6 3 3 4 1 2 5 3 4 5 5 6 10 3 5 -100 4 6 -100 1 3 -10
output:
NO PATH NO PATH 5 0 -95 -100
result:
ok 6 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 5700kb
input:
100 500 500 4 13 20 329 41 10 63 100 90 297 15 79 163 24 67 747 29 68 443 73 98 565 10 41 921 79 62 973 31 85 270 25 29 672 34 43 391 30 92 604 58 82 90 28 16 460 53 63 350 91 98 260 70 22 232 5 36 335 37 32 339 4 48 940 85 1 233 95 78 323 62 79 688 49 57 576 10 54 103 33 78 541 88 22 171 4 48 408 2...
output:
-3619 -3536 NO PATH 0 NO PATH -7205 -6588 -2243 -2898 -691 -6755 -710 -4236 -3929 -941 -4827 -4796 NO PATH -6827 -4246 -4759 -1991 -5025 -1522 -6643 -6453 -3084 -4740 -6448 -5552 -3800 -2700 -7006 -3915 -433 NO PATH -2767 NO PATH 158 -2524 -628 -7166 -3859 -2838 -2168 -7106 -2726 112 -3844 544 -3860...
result:
ok 100 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
50 100 50 24 26 39 94 44 42 47 15 39 28 10 25 37 28 12 3 36 22 34 9 36 74 28 12 35 25 22 63 48 7 86 29 37 69 9 10 4 36 9 31 28 34 54 6 1 89 33 25 17 36 10 47 5 35 9 7 14 65 44 50 96 31 1 35 37 29 4 28 34 27 35 18 74 34 8 37 13 17 2 19 48 47 20 43 98 26 16 91 13 29 63 20 43 48 5 35 54 39 15 69 10 33 ...
output:
NO PATH -3 NO PATH NO PATH -126 NO PATH -2 -98 -66 -62 -38 -144 51 15 NO PATH NO PATH 49 -43 -5 NO PATH 67 -79 NO PATH 0 -64 NO PATH -57 -141 114 -73 NO PATH 27 -81 -114 -117 -45 118 NO PATH NO PATH -85 NO PATH -94 NO PATH -47 -35 NO PATH -91 -15 -57 -52
result:
ok 50 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
300 2000 1000 208 251 61 2246 22 3 3153 81 124 1726 77 280 4372 14 169 592 186 46 4946 146 128 4639 148 296 2647 283 120 4786 197 139 435 59 89 4916 231 38 506 182 56 623 283 225 3941 298 117 3457 141 24 1734 18 10 1102 86 45 813 261 271 2541 19 263 3219 250 260 3725 131 298 110 285 237 331 292 184 ...
output:
-41459 -14899 -27143 -9932 -10727 -18844 -27091 -10217 -7973 1635 -5432 -29336 -10123 -10958 -6204 -18534 -38070 1002 -2183 1288 -27814 -27410 -38724 -33495 -39524 -26651 -7308 -13916 -29867 -37448 -13090 -28028 -10532 -7565 7438 -18717 -37908 -34214 -1458 -7125 -43190 -7876 -39417 -10082 -25107 -63...
result:
ok 300 lines
Test #5:
score: -100
Wrong Answer
time: 14ms
memory: 5492kb
input:
5000 30000 30000 617 2616 3637 3037 1979 3188 582 3728 2476 2258 27 928 3410 4874 2914 1786 2307 916 4445 2888 299 1338 4271 9 328 3334 3112 2859 622 3874 2702 2754 1859 9598 2143 4393 2760 3714 4390 9070 205 1820 9332 2148 2583 2933 3483 4113 8894 1181 4261 7130 4053 1552 4229 4895 3533 2174 4893 1...
output:
-10051 -115110 -87521 NO PATH -50929 NO PATH -136162 -81955 NO PATH NO PATH NO PATH -58600 -63899 -53909 -68434 -113864 -91727 NO PATH -11515 NO PATH NO PATH NO PATH NO PATH -91076 -64069 -85891 NO PATH -47627 -96886 -119979 -21989 -15432 -104491 NO PATH -26025 -63357 NO PATH -23575 -34104 -36376 -3...
result:
wrong answer 1st lines differ - expected: '-67443', found: '-10051'