QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#118650#4303. New Levelzym417WA 1ms11576kbC++141.8kb2023-07-03 20:06:392023-07-03 20:06:42

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 20:06:42]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:11576kb
  • [2023-07-03 20:06:39]
  • 提交

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;
}

詳細信息

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