QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#202023 | #1774. Customs Controls | dog_of_zimu | WA | 1ms | 5732kb | C++14 | 2.4kb | 2023-10-05 18:32:12 | 2023-10-05 18:32:12 |
Judging History
answer
#include<cstdio>
#include<iostream>
#include<queue>
using namespace std;
namespace LZZMD{
const int N = 1e5, M = 2e5, inf = 0x7fffffff / 2;
struct edge{
int nxt, to;
} e[M * 6 + 10];
int head[N * 3 + 10], cnt;
int time[N + 10];
int n, m, k;
inline void add(int u, int v){
e[++cnt] = {head[u], v};
head[u] = cnt;
}
struct node{
int u, dis;
};
priority_queue<node> q;
bool operator < (node x, node y){
return x.dis > y.dis;
}
int dis[N + 10], vis[N + 10];
inline void dijkstra(int s){
for(int i = 1; i <= n; i++)
dis[i] = inf;
dis[s] = time[s];
q.push({s, dis[s]});
while(q.size()){
int u = q.top().u;
q.pop();
if(vis[u])
continue;
vis[u] = 1;
for(int i = head[u]; i; i = e[i].nxt){
int v = e[i].to;
if(dis[v] > dis[u] + time[v]){
dis[v] = dis[u] + time[v];
q.push({v, dis[v]});
}
}
}
}
int rd[N + 10], que[N + 10], f[N + 10][2];
bool ans[N + 10], ans1 = true, ans2 = false;
void print(int u){
if(f[u - 2 * n][0] <= f[u - 2 * n][1]){
ans[u - 2 * n] = ans2;
for(int i = head[u]; i; i = e[i].nxt)
print(e[i].to);
}
else{
ans[u - 2 * n] = ans1;
for(int i = head[u]; i; i = e[i].nxt)
ans[e[i].to - 2 * n] = ans1;
}
}
int main(){
scanf("%d%d%d", &n, &m, &k);
for(int i = 1; i <= n; i++)
scanf("%d", &time[i]);
for(int i = 1, u, v; i <= m; i++){
scanf("%d%d", &u, &v);
add(u, v), add(v, u);
}
dijkstra(1);
for(int u = 1; u <= n; u++)
for(int i = head[u]; i; i = e[i].nxt)
if(dis[e[i].to] + time[u] == dis[u])
add(e[i].to + n, u + n), add(u + 2 * n, e[i].to + 2 * n), rd[u]++;
int l = 0, r = 0;
que[r++] = {n + 1};
while(l != r){
int u = que[l];
l = (l + 1) % N;
for(int i = head[u]; i; i = e[i].nxt){
int v = e[i].to;
rd[v - n]--;
f[v - n][0] = f[v - n][0] + min(f[u - n][0], f[u - n][1]);
f[v - n][1]++;
if(!rd[v - n])
que[r] = v, r = (r + 1) % N;
}
}
if(min(f[n][0], f[n][1]) > k && min(f[n][0], f[n][1]) > n - k){
puts("impossible");
return 0;
}
int tmp = min(f[n][0], f[n][1]);
if(tmp > k){
k = n - k;
swap(ans1, ans2);
}
print(n * 3);
for(int i = 1; i <= n; i++){
if(tmp < k && ans[i] == ans2)
ans[i] = ans1, tmp++;
putchar(ans[i] ? 'N' : 'S');
}
return 0;
}
}
int main(){
return LZZMD::main();
}
//14MB
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5732kb
input:
5 10 2 1 1 1 1 1 3 4 5 4 3 1 4 1 3 5 2 1 2 4 2 5 1 5 2 3
output:
NNSSS
result:
wrong answer an alternating shortest path existed