QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#118569 | #4303. New Level | include_BM | TL | 96ms | 95560kb | C++14 | 1.4kb | 2023-07-03 17:27:18 | 2023-07-03 17:27:19 |
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()-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: 3ms
memory: 72252kb
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: 6ms
memory: 72796kb
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: 0
Accepted
time: 4ms
memory: 74232kb
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 8 6 8 9 7 9 8 8 10 10 9 9 9 10 10 1 1 8 2 2 3 4 3 4 4 4 5 5 3 5 6 6 4 7 7 7 5 8 6 8 9 7 9 10 8 9 8 10 8 1 2 9 2 9 3 4 3 3 5 5 4 4 6 7 3 4 6 8 7 5 6 7 7 8 9 7 8 10 10 1 1 9 1 10 2 2 2 3 3 1 3 3 2 4 5 6 5 5 6 6 6 6 5 7 7 8 6 6 7 7 8 7 8 9 9 8 10 10 1 10 2 2 2 3 3 4 4 1 4 5 5 4 4 6 7 6 8 7 7 7 ...
result:
ok n=239, m=238, k=10
Test #4:
score: 0
Accepted
time: 9ms
memory: 73272kb
input:
2392 2391 100 89 13 96 29 35 81 10 62 30 4 46 56 15 37 61 8 45 47 5 29 23 64 98 50 18 34 28 24 20 24 10 43 34 28 64 100 61 22 68 37 61 49 37 74 64 53 1 84 54 30 46 25 21 31 96 49 74 19 4 10 29 72 27 48 28 99 74 8 32 89 46 68 73 87 41 72 25 2 27 66 77 90 24 78 65 34 67 25 11 9 16 17 87 2 56 58 48 56 ...
output:
88 89 90 90 91 90 91 92 91 90 91 92 93 91 94 93 90 93 92 93 89 92 89 93 90 93 91 93 90 93 91 94 92 91 90 93 93 95 95 94 92 94 94 91 93 96 93 91 91 94 91 93 89 92 92 91 95 93 92 95 96 94 94 93 95 94 96 93 91 93 94 95 92 97 94 92 96 92 95 97 92 97 95 92 93 97 93 92 90 92 92 89 95 94 96 94 90 89 91 91 ...
result:
ok n=2392, m=2391, k=100
Test #5:
score: 0
Accepted
time: 11ms
memory: 72776kb
input:
4 3 3 1 3 1 2 2 1 3 2 4 2
output:
1 3 1 2
result:
ok n=4, m=3, k=3
Test #6:
score: 0
Accepted
time: 3ms
memory: 72688kb
input:
5000 4999 215 75 104 70 136 199 28 108 67 92 90 200 35 184 21 81 200 48 193 172 143 109 43 89 94 195 149 176 198 96 101 199 207 112 29 7 123 59 3 14 38 99 152 188 15 188 179 47 190 199 117 3 63 187 77 14 166 41 8 7 209 211 95 6 80 174 135 211 95 211 189 180 118 210 20 111 24 192 67 129 116 182 17 17...
output:
9 10 10 11 12 11 13 11 13 12 14 10 11 11 10 12 13 11 14 15 16 14 12 12 14 14 13 14 15 15 12 17 11 16 11 13 13 14 13 10 12 13 16 10 16 13 18 11 13 11 12 12 11 16 10 11 12 13 12 17 14 13 17 13 14 19 12 12 13 13 14 16 12 17 12 13 13 17 14 14 14 17 13 17 12 12 20 19 14 14 15 14 14 14 15 18 12 15 14 14 1...
result:
ok n=5000, m=4999, k=215
Test #7:
score: 0
Accepted
time: 7ms
memory: 73840kb
input:
5000 4999 215 155 162 166 204 39 176 58 184 65 113 129 76 118 27 143 103 22 1 209 135 32 117 55 152 197 66 199 5 186 166 53 101 34 91 148 2 70 51 202 80 1 41 31 143 44 102 145 13 90 100 163 185 211 77 45 48 26 123 4 104 20 168 154 142 90 153 149 163 38 172 29 133 62 189 107 89 37 210 57 24 25 55 123...
output:
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166...
result:
ok n=5000, m=4999, k=215
Test #8:
score: 0
Accepted
time: 10ms
memory: 79656kb
input:
100000 99999 215 144 87 149 51 25 51 108 78 135 17 73 188 186 148 9 184 206 1 35 53 29 31 200 78 63 136 158 54 153 103 71 83 60 94 89 7 215 85 150 179 210 130 161 112 93 213 106 189 162 43 173 141 185 192 160 210 196 197 185 33 136 85 103 150 197 140 202 45 51 133 177 16 66 106 70 140 35 66 14 112 1...
output:
78 79 80 80 81 79 80 79 81 82 80 82 82 80 83 80 81 79 82 82 83 80 83 81 82 82 83 82 81 80 84 85 82 83 84 81 80 83 86 81 81 81 82 81 82 81 80 83 81 83 83 85 84 81 81 83 86 82 84 84 82 80 86 82 83 83 82 84 79 81 81 84 80 83 82 83 81 84 84 83 83 84 85 84 83 83 83 83 81 83 84 82 80 84 82 83 81 84 85 83 ...
result:
ok n=100000, m=99999, k=215
Test #9:
score: 0
Accepted
time: 19ms
memory: 79676kb
input:
100000 99999 215 8 183 153 16 17 143 160 152 91 68 8 161 194 91 107 15 206 155 125 10 109 22 77 17 151 148 175 139 182 167 153 115 16 113 58 182 191 203 215 106 34 159 17 182 139 44 30 129 105 134 57 157 32 56 214 5 62 180 175 61 120 15 214 97 103 24 209 194 127 87 204 89 156 2 36 74 114 163 206 97 ...
output:
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2...
result:
ok n=100000, m=99999, k=215
Test #10:
score: 0
Accepted
time: 49ms
memory: 82296kb
input:
239239 239238 239 146 41 60 184 200 183 12 18 119 159 195 222 203 34 50 160 207 170 130 87 232 87 92 221 84 33 38 237 187 102 50 204 3 135 227 23 110 116 215 28 27 238 239 91 153 214 233 193 77 167 203 167 83 200 214 234 68 188 232 197 67 17 210 199 17 222 103 213 99 212 159 76 134 182 89 134 44 92 ...
output:
180 181 181 182 183 182 181 182 182 183 182 182 183 183 183 183 184 185 182 184 184 184 182 184 186 185 183 183 184 184 186 183 184 182 183 183 184 185 186 182 181 187 185 187 183 185 184 184 184 184 185 181 185 184 183 186 183 184 186 182 183 184 182 183 184 184 182 185 185 186 183 185 186 185 185 ...
result:
ok n=239239, m=239238, k=239
Test #11:
score: 0
Accepted
time: 11ms
memory: 75456kb
input:
73223 73222 456 176 375 93 323 28 186 232 176 6 374 42 15 169 308 221 137 388 221 345 86 170 251 432 288 394 21 122 351 430 78 216 133 119 278 100 163 46 278 294 234 68 239 64 202 41 194 410 253 352 153 333 363 120 379 235 286 412 299 20 71 139 369 306 390 327 78 165 245 313 275 6 140 274 417 335 24...
output:
359 360 360 361 362 363 361 361 360 360 363 364 361 360 361 364 361 362 365 364 363 361 364 364 361 361 361 362 364 361 362 366 364 365 365 361 364 362 362 364 363 362 365 361 365 361 363 362 363 366 362 365 360 366 362 362 363 364 362 363 366 364 363 363 365 367 362 361 366 365 363 367 365 365 363 ...
result:
ok n=73223, m=73222, k=456
Test #12:
score: 0
Accepted
time: 96ms
memory: 95560kb
input:
500000 499999 120 120 109 52 88 118 102 96 49 54 40 65 119 104 14 83 86 70 71 108 13 89 86 79 93 2 3 84 120 10 22 116 111 41 2 25 18 65 70 99 99 107 21 75 98 24 95 106 40 40 77 26 103 53 63 35 120 80 56 38 35 82 24 108 26 35 88 47 53 29 8 15 53 89 67 109 69 64 9 51 3 2 99 48 11 82 90 47 91 47 31 9 7...
output:
39 40 41 40 40 41 42 43 42 42 41 42 43 43 42 41 41 41 44 43 43 44 42 42 42 41 45 46 41 42 44 43 42 40 43 43 43 43 45 47 44 42 43 44 44 45 46 42 41 41 43 44 43 45 42 41 44 44 45 44 45 42 44 43 43 46 45 41 45 45 41 44 42 42 40 43 44 41 45 45 42 43 45 44 44 43 44 46 48 42 45 43 46 42 46 43 45 45 45 44 ...
result:
ok n=500000, m=499999, k=120
Test #13:
score: 0
Accepted
time: 7ms
memory: 73280kb
input:
3 2 2 1 2 2 2 1 3 1
output:
2 1 1
result:
ok n=3, m=2, k=2
Test #14:
score: 0
Accepted
time: 1ms
memory: 73992kb
input:
4 3 3 2 1 3 1 2 1 3 2 4 1
output:
2 1 3 1
result:
ok n=4, m=3, k=3
Test #15:
score: 0
Accepted
time: 13ms
memory: 72388kb
input:
2 1 2 1 2 2 1
output:
2 1
result:
ok n=2, m=1, k=2
Test #16:
score: 0
Accepted
time: 7ms
memory: 73880kb
input:
10 45 10 1 2 3 4 5 6 7 8 9 10 1 3 1 4 1 5 1 9 2 1 2 4 2 5 2 8 2 9 2 10 3 2 3 7 3 8 3 10 4 3 4 6 4 7 4 10 5 3 5 4 5 8 6 1 6 2 6 3 6 5 6 8 7 1 7 2 7 5 7 6 7 9 7 10 8 1 8 4 8 7 9 3 9 4 9 5 9 6 9 8 10 1 10 5 10 6 10 8 10 9
output:
10 1 2 3 4 5 6 7 8 9
result:
ok n=10, m=45, k=10
Test #17:
score: -100
Time Limit Exceeded
input:
1000 499500 1000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 9...