QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#522269 | #7048. Delivery Route | QFshengxiu | WA | 2ms | 9844kb | C++20 | 3.0kb | 2024-08-16 20:35:19 | 2024-08-16 20:35:19 |
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 inf 0x3f3f3f3f3f3f3f3f
#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;
mt19937_64 rnd(chrono::duration_cast<chrono::nanoseconds>(chrono::system_clock::now().time_since_epoch()).count());
constexpr int N = 3e5 + 10;
int n, x, y, s, tot, dn;
int vis[N], fa[N], ru[N];
int dis[N];
vector<PII> g[N], e[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 dij(int rt)
{
priority_queue<PII> q;
for (auto u : scc[rt])
{
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 <= y; i++)
{
int u, v, w;
cin >> u >> v >> w;
g[u].push_back({v, w});
ru[v]++;
}
for (int i = 1; i <= n; i++)
{
scc[find(i)].push_back(i);
}
queue<int> q;
dis[s] = 0;
for (int i = 1; i <= n; i++)
{
if (!ru[find(i)] && !vis[find(i)])
{
q.push(find(i));
vis[find(i)] = true;
}
}
while (!q.empty())
{
auto p = q.front();
q.pop();
dij(p);
for (auto v : scc[p])
{
if (dis[v] != inf)
{
for (auto [x, w] : g[v])
{
dis[x] = min(dis[x], dis[v] + w);
}
}
ru[find(v)]--;
if (!ru[find(v)])
q.push(find(v));
}
}
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;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9844kb
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: -100
Wrong Answer
time: 2ms
memory: 9804kb
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:
NO PATH NO PATH NO PATH 0 NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO PATH NO...
result:
wrong answer 1st lines differ - expected: '-3619', found: 'NO PATH'