QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#118650 | #4303. New Level | zym417 | WA | 1ms | 11576kb | C++14 | 1.8kb | 2023-07-03 20:06:39 | 2023-07-03 20:06:42 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read() {
int res = 0, f = 1; char ch;
while((ch = getchar()) && (ch < '0' || ch > '9') && ch != '-');
(ch == '-') ? f = -1 : res = ch - '0';
while((ch = getchar()) && ch >= '0' && ch <= '9') res = (res << 3) + (res << 1) + ch - '0';
return res * f;
}
inline void print(int x, char ch = '\n') {
if(x < 0) putchar('-'), x = -x;
static short prnum[21];
short prcnt = 0;
do { prnum[++prcnt] = x % 10; x /= 10; } while(x > 0);
while(prcnt) putchar(prnum[prcnt--] + '0');
putchar(ch);
}
const int MAXN = 5e5 + 5, INF = 1e18;
int n, m, K, a[MAXN], dis[MAXN];
int tot, hd[MAXN], to[MAXN << 1], nt[MAXN << 1], w[MAXN << 1];
bool vis[MAXN];
inline void add(int x, int y) {
to[++tot] = y, nt[tot] = hd[x], hd[x] = tot, w[tot] = ((a[y] + 1 - a[x] + K) % K + K) % K;
to[++tot] = x, nt[tot] = hd[y], hd[y] = tot, w[tot] = ((a[x] + 1 - a[y] + K) % K + K) % K;
}
struct node {
int w, id;
bool operator < (const node &x) const { return w > x.w; }
}; priority_queue<node> q;
signed main() {
n = read(); m = read(); K = read();
for(int i = 1; i <= n; i++) a[i] = read();
for(int i = 1, x, y; i <= m; i++) {
x = read(); y = read();
add(x, y);
}
for(int i = 1; i <= n; i++) dis[i] = INF;
q.push({0, 1}); dis[1] = 0;
while(q.size()) {
int x = q.top().id; q.pop();
if(vis[x]) continue; vis[x] = true;
for(int i = hd[x]; i; i = nt[i])
if(dis[to[i]] > dis[x] + w[i]) {
dis[to[i]] = dis[x] + w[i];
q.push({dis[to[i]], to[i]});
}
}
for(int i = 1; i <= n; i++) print(((a[i] - dis[i]) % K + K) % K + 1, ' ');
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 11576kb
input:
4 4 4 1 2 3 1 1 2 1 3 2 3 3 4
output:
2 1 1 4
result:
wrong answer Vertices 2 and 3 have the same color