QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#118521 | #4303. New Level | lyx123886a123886 | WA | 2ms | 9716kb | C++14 | 1.8kb | 2023-07-03 16:53:55 | 2023-07-03 16:53:59 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int read() {
char ch=getchar();int res=0,fl=1;
while(ch<'0'||ch>'9'){if(ch=='-') fl=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){res=res*10+ch-'0';ch=getchar();}
return res*fl;
}
#define ll long long
struct node{
int u;
ll dis;
};
bool operator <(node A,node B) {return A.dis>B.dis;}
priority_queue<node> q;
const int N=500050;
#define inf 1000000000000
ll dis[N];int vis[N];
int nex[N<<1],fir[N],v[N<<1],w[N<<1],__cnt=0,c[N],n,mod,m;
void addedge(int x,int y,int z) {
nex[++__cnt]=fir[x];
fir[x]=__cnt;
v[__cnt]=y;
w[__cnt]=z;
return ;
}
void dijkstra(int S) {
for(int i=1;i<=n;++i) dis[i]=inf;
dis[S]=0;
vis[S]=1;
q.push((node){S,dis[S]});
while(!q.empty()) {
int u=q.top().u;
q.pop();
if(vis[u]) continue;
vis[u]=1;
for(int i=fir[u];i;i=nex[i]) {
int to=v[i];
if(dis[to]>dis[u]+w[i]) {
dis[to]=dis[u]+w[i];
q.push((node){u,dis[u]});
}
}
}
return ;
}
int fa[N];
int get_fa(int x) {return (fa[x]==x)?x:get_fa(fa[x]);}
int merge(int x,int y) {
x=get_fa(x);y=get_fa(y);
if(x==y) return 0;
fa[x]=y;
return 1;
}
struct edge{
int u,v;
}e[N];
int tot=0;
int d(int x,int y){return (c[y]-c[x]-1+mod)%mod;}//x->y
int main()
{
//freopen("past.in","r",stdin);
//freopen("past.out","w",stdout);
n=read();m=read();mod=read();
for(int i=1;i<=n;++i) c[i]=read()-1;
for(int i=1;i<=m;++i) {
e[i].u=read();
e[i].v=read();
if(!d(e[i].u,e[i].v)||!d(e[i].v,e[i].u)) merge(e[i].u,e[i].v);
}
for(int i=1;i<=m;++i) {
int fx=get_fa(e[i].u),fy=get_fa(e[i].v);
if(fx==fy) continue;
addedge(fx,fy,d(e[i].u,e[i].v));
addedge(fy,fx,d(e[i].v,e[i].u));
}
dijkstra(get_fa(1));
for(int i=1;i<=m;++i) printf("%lld ",((c[i]+inf-dis[get_fa(i)])%mod+mod)%mod+1);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 9716kb
input:
4 4 4 1 2 3 1 1 2 1 3 2 3 3 4
output:
1 2 3 1
result:
wrong answer Problem condition is not satisfied