QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#56606 | #4382. Path | qinjianbin | AC ✓ | 505ms | 60096kb | C++17 | 1.5kb | 2022-10-20 16:24:51 | 2022-10-20 16:24:52 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define _for(i, a, b) for(int i = (a); i <= (b); i++)
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
struct node
{
int v; ll w; int ty;
bool operator < (const node& rhs) const
{
return w > rhs.w;
}
};
vector<node> g[N];
int vis[N], id, n, m, s, k;
ll d[N][2];
void solve()
{
set<int> S;
priority_queue<node> q;
_for(i, 1, n) d[i][0] = d[i][1] = 1e18, S.insert(i);
d[s][0] = id = 0;
q.push({s, 0, 0});
while(!q.empty())
{
auto [u, w, ty] = q.top(); q.pop();
S.erase(u);
if(ty) //如果上一次走了特殊边
{
id++;
for(auto [v, w2, ty2]: g[u]) vis[v] = id;
vector<int> del;
for(int x: S)
if(vis[x] != id)
{
del.push_back(x);
d[x][0] = d[u][ty];
q.push({x, d[x][0], 0});
}
for(int x: del) S.erase(x);
}
int t = ty ? -k : 0;
for(auto [v, w2, ty2]: g[u])
if(d[u][ty] + w2 + t < d[v][ty2])
{
d[v][ty2] = d[u][ty] + w2 + t;
q.push({v, d[v][ty2], ty2});
}
}
}
int main()
{
int T; scanf("%d", &T);
while(T--)
{
scanf("%d%d%d%d", &n, &m, &s, &k);
_for(i, 1, n) vis[i] = 0, g[i].clear();
while(m--)
{
int u, v, w, ty;
scanf("%d%d%d%d", &u, &v, &w, &ty);
g[u].push_back({v, w, ty});
}
solve();
_for(i, 1, n)
{
ll cur = min(d[i][0], d[i][1]);
printf("%lld ", cur == 1e18 ? -1 : cur);
}
puts("");
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 505ms
memory: 60096kb
input:
13 10 30 2 18468 5 1 37637 0 9 9 45430 0 6 6 41749 0 2 2 21463 1 8 7 50859 0 3 4 18760 0 2 7 38186 0 8 7 33239 0 10 3 44135 0 6 5 47171 0 3 4 36141 0 2 2 46721 0 8 5 51130 0 8 10 27191 0 10 9 30784 0 1 3 18756 0 1 3 37732 0 7 6 34358 0 1 1 33474 0 4 9 38097 0 5 5 37224 0 7 7 32399 0 5 10 43094 0 8 9...
output:
21463 0 21463 21463 21463 45392 38186 21463 21463 21463 41923 0 45987 49920 18690 52316 71251 52316 25059 52316 57062 34860 18647 36256 49111 29152 32554 62744 0 38939 56122 64474 0 -1 84001 29542 39504 -1 -1 38273 46451 44825 44825 44825 57660 38488 44825 44825 44825 0 51281 91636 44602 39997 ...
result:
ok 13 lines