QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#784354 | #1774. Customs Controls | ydzr00000 | WA | 2ms | 10404kb | C++17 | 2.6kb | 2024-11-26 14:45:00 | 2024-11-26 14:45:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
vector<int>e[100001],g[100001];
int a[100001];
struct vertex{
int id;
long long dis;
friend inline bool operator<(const vertex &a,const vertex &b)
{
return a.dis>b.dis;
}
};
priority_queue<vertex>Q;
vector<long long>dis[2];
bool vis[100001];
inline void Dijkstra(int s,vector<long long>&dis)
{
memset(vis,0,sizeof(vis));
fill(dis.begin(),dis.end(),1e12);
dis[s]=0;
Q.push({s,0});
while(!Q.empty())
{
auto [u,d]=Q.top();
Q.pop();
if(vis[u])
continue;
vis[u]=true;
for(auto to: e[u])
{
long long nw=d+a[to];
if(nw>dis[to])
{
dis[to]=nw;
Q.push({to,nw});
}
}
}
}
vector<pair<int,int>>Eset;
char ch[300001];
int in[300001];
int main(){
int n,m,k;
scanf("%d %d %d",&n,&m,&k);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
bool flg=false;
for(int i=1;i<=m;i++)
{
int u,v;
scanf("%d %d",&u,&v);
e[u].push_back(v);
e[v].push_back(u);
flg|=(u==1&&v==n);
flg|=(u==n&&v==1);
Eset.push_back({u,v});
}
dis[0].resize(n+1);
dis[1].resize(n+1);
Dijkstra(1,dis[0]);
Dijkstra(n,dis[1]);
for(auto [u,v]: Eset)
{
if(dis[0][u]+dis[1][v]==dis[0][n])
g[u].push_back(v),in[v]++;
if(dis[0][v]+dis[1][u]==dis[0][n])
g[v].push_back(u),in[u]++;
}
fill(ch+1,ch+n+1,'S');
if(flg)
{
if(n==2&&k==1)
{
puts("impossible");
return 0;
}
if(k>1)
{
ch[1]=ch[n]='N';
k-=2;
int now=2;
while(k)
{
ch[now]='N';
now++;
k--;
}
}
else if(k==1)
ch[2]='N';
}
else
{
queue<int>Q;
vector<int>ord;
for(int i=1;i<=n;i++)
if(!in[i])
Q.push(i);
while(!Q.empty())
{
int u=Q.front();
Q.pop();
ord.push_back(u);
for(auto to: g[u])
{
in[to]--;
if(!in[to])
Q.push(to);
}
}
for(int i=0;i<k;i++)
ch[ord[i]]='N';
}
string ans="";
for(int i=1;i<=n;i++)
ans+=ch[i];
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9068kb
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:
NSSSN
result:
ok accepted
Test #2:
score: 0
Accepted
time: 0ms
memory: 9712kb
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: 9140kb
input:
2 1 2 6124 7094 2 1
output:
NN
result:
ok accepted
Test #4:
score: 0
Accepted
time: 1ms
memory: 8816kb
input:
2 1 1 6901 1417 2 1
output:
impossible
result:
ok accepted
Test #5:
score: 0
Accepted
time: 0ms
memory: 9316kb
input:
50 67 25 5 10 5 4 3 3 8 7 10 4 6 6 9 8 5 1 5 9 3 2 3 8 9 9 2 8 7 8 9 8 3 3 10 7 5 5 7 1 6 9 4 6 9 10 4 10 9 10 9 5 45 35 27 17 11 14 34 1 49 37 4 2 9 3 42 9 13 25 40 32 38 17 28 1 26 14 13 19 41 40 38 40 12 6 14 7 47 25 30 21 32 22 7 6 16 12 15 9 20 16 29 3 21 8 19 9 18 23 43 5 5 3 11 35 10 7 36 16 ...
output:
NSSNNSNNNNNNNNNNNNNNNNNNNNNSNSSSSSSSSSSSSSSSSSSSSS
result:
ok accepted
Test #6:
score: -100
Wrong Answer
time: 2ms
memory: 10404kb
input:
100 99 50 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 34 11 79 3 36 30 59 24 83 14 88 23 19 9 44 19 91 11 40 14 58 37 99 30 45 12 81 66 38 35 73...
output:
NSSNNNNSSNNNNNSNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNSNNNNNNNSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
result:
wrong answer an alternating shortest path existed