QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#118648 | #4303. New Level | zym417 | WA | 2ms | 9528kb | C++14 | 1.8kb | 2023-07-03 20:02:47 | 2023-07-03 20:02:51 |
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;
to[++tot] = x, nt[tot] = hd[y], hd[y] = tot, w[tot] = (a[x] + 1 - a[y] + 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(((INF - dis[i]) % K + K) % K + 1, ' ');
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 9528kb
input:
4 4 4 1 2 3 1 1 2 1 3 2 3 3 4
output:
1 3 2 3
result:
ok n=4, m=4, k=4
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 9516kb
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:
2 2 3 3 1 2 3 2 1 2
result:
wrong answer Vertices 2 and 1 have the same color