QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#118566 | #4303. New Level | include_BM | WA | 6ms | 73072kb | C++14 | 1.4kb | 2023-07-03 17:26:54 | 2023-07-03 17:26:56 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read(){
ll x(0),f(0); char ch=getchar();
while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar();
while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return f?-x:x;
}
const int N=2e6+10;
int n,m,k,c[N],u[N],v[N],head[N],cnt; ll dis[N]; vector<int> G[N];
struct edge{
int to,nxt,w;
}e[N];
inline void add(int u,int v,int w){
e[++cnt].to=v,e[cnt].nxt=head[u],e[cnt].w=w,head[u]=cnt;
}
inline int mod(int x){return (x%k+k)%k;}
struct node{
int x; ll dis;
node(int _x,ll _dis):x(_x),dis(_dis){}
friend bool operator < (node a,node b){return a.dis>b.dis;}
};
signed main(){
n=read(),m=read(),k=read();
for(int i=1;i<=n;++i) c[i]=read();
for(int i=1;i<=m;++i){
u[i]=read(),v[i]=read();
add(u[i],v[i],min(mod(c[v[i]]+1-c[u[i]]),mod(c[v[i]]-1-c[u[i]])));
add(v[i],u[i],min(mod(c[u[i]]+1-c[v[i]]),mod(c[u[i]]-1-c[v[i]])));
}
memset(dis,0x3f,sizeof dis);
priority_queue<node> q; q.emplace(1,0),dis[1]=0;
while(!q.empty()){
int u=q.top().x; q.pop();
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].to;
if(dis[u]+e[i].w<dis[v]) dis[v]=dis[u]+e[i].w,q.emplace(v,dis[v]);
}
}
for(int i=1;i<=n;++i) c[i]=(c[i]+dis[0]-dis[i])%k,printf("%d ",c[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 73072kb
input:
4 4 4 1 2 3 1 1 2 1 3 2 3 3 4
output:
0 1 2 3
result:
wrong answer Integer 0 violates the range [1, 4]