QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#202007 | #1774. Customs Controls | dog_of_zimu | WA | 1ms | 7836kb | C++14 | 2.0kb | 2023-10-05 18:19:55 | 2023-10-05 18:19:56 |
Judging History
answer
#include<cstdio>
#include<iostream>
#include<queue>
#define int long long
using namespace std;
namespace LZZMD{
const int N = 1e5, M = 2e5, inf = 0x7fffffffffffffff / 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]});
}
}
}
}
bool ans[N + 10];
int main(){
scanf("%lld%lld%lld", &n, &m, &k);
for(int i = 1; i <= n; i++)
scanf("%lld", &time[i]);
for(int i = 1, u, v; i <= m; i++){
scanf("%lld%lld", &u, &v);
add(u, v), add(v, u);
}
dijkstra(1);
int s1 = 1, s2 = 1;
for(int i = head[1]; i; i = e[i].nxt)
if(dis[1] + time[e[i].to] == dis[e[i].to])
s1++;
for(int i = head[n]; i; i = e[i].nxt)
if(dis[e[i].to] + time[n] == dis[n])
s2++;
int tmp;
if(s1 <= s2){
tmp = s1;
ans[1] = 1;
for(int i = head[1]; i; i = e[i].nxt)
if(dis[1] + time[e[i].to] == dis[e[i].to])
ans[e[i].to] = 1;
}
else{
tmp = s2;
ans[n] = 1;
for(int i = head[n]; i; i = e[i].nxt)
if(dis[e[i].to] + time[n] == dis[n])
ans[e[i].to] = 1;
}
int flag = 0;
if(k < n - k)
k = n - k, flag = 1;
for(int i = 1; i <= n; i++){
if(!ans[i] && tmp < k)
ans[i] = 1, tmp++;
if(!flag)
putchar(ans[i] ? 'N' : 'S');
else
putchar(ans[i] ? 'S' : 'N');
}
return 0;
}
}
signed main(){
return LZZMD::main();
}
//14MB
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7836kb
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:
SSNNS
result:
ok accepted
Test #2:
score: 0
Accepted
time: 1ms
memory: 7816kb
input:
10 9 5 1 1 1 1 1 1 1 1 1 1 9 5 7 1 8 1 10 1 5 3 6 1 2 1 3 2 4 1
output:
NNNNSSSSSN
result:
ok accepted
Test #3:
score: 0
Accepted
time: 1ms
memory: 5840kb
input:
2 1 2 6124 7094 2 1
output:
NN
result:
ok accepted
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 7756kb
input:
2 1 1 6901 1417 2 1
output:
NN
result:
wrong answer number of N:s not equal to k