QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#118560#4303. New Levelinclude_BMWA 12ms74712kbC++141.4kb2023-07-03 17:24:132023-07-03 17:24:14

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-03 17:24:14]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:74712kb
  • [2023-07-03 17:24:13]
  • 提交

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;
    e[++cnt].to=u,e[cnt].nxt=head[v],e[cnt].w=w,head[v]=cnt;
}

inline int mod(int x){return (x%k+k)%k;}

struct node{
    int x,dis;
    node(int _x,int _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()-1;
	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]+1);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 72880kb

input:

4 4 4
1 2 3 1
1 2
1 3
2 3
3 4

output:

4 1 2 3 

result:

ok n=4, m=4, k=4

Test #2:

score: 0
Accepted
time: 12ms
memory: 74712kb

input:

10 9 3
3 2 3 3 1 2 3 1 1 2
2 1
3 2
4 2
5 3
6 5
7 6
8 6
9 7
10 9

output:

3 2 3 3 1 2 3 1 1 2 

result:

ok n=10, m=9, k=3

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 72764kb

input:

239 238 10
6 1 2 10 9 1 8 10 1 10 6 4 5 2 7 8 4 9 7 5 1 3 2 8 1 7 3 4 6 4 2 6 3 10 3 10 5 1 8 8 1 1 2 3 5 5 5 9 3 8 3 4 7 10 7 5 7 8 2 6 8 10 3 3 2 1 7 5 1 4 4 1 9 9 4 2 10 1 6 10 5 3 8 4 4 10 4 4 2 9 9 6 6 8 2 3 2 4 8 5 10 10 3 3 5 1 4 8 4 2 3 6 10 4 10 2 8 2 2 5 7 5 3 3 8 1 7 10 2 8 2 6 3 10 6 5 9...

output:

5 6 7 6 2 6 10 3 7 3 8 8 4 4 9 9 3 10 4 1 1 2 2 6 7 10 7 8 8 8 5 9 7 1 6 10 8 1 7 7 1 8 2 8 9 3 9 10 10 9 10 2 8 5 10 1 10 9 1 2 1 1 7 7 6 2 8 5 5 6 4 8 5 7 8 5 1 2 3 1 6 8 4 7 9 7 7 8 4 8 8 3 3 7 9 9 8 10 1 6 3 3 4 4 4 4 3 5 5 6 4 4 5 5 8 7 2 9 9 8 10 10 7 10 8 4 8 9 9 2 10 7 10 3 9 8 2 4 7 10 8 5 ...

result:

wrong answer Problem condition is not satisfied