QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#118565#4303. New LevelooooxxxxWA 34ms41840kbC++141.7kb2023-07-03 17:26:462023-07-03 17:26:50

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:26:50]
  • 评测
  • 测评结果:WA
  • 用时:34ms
  • 内存:41840kb
  • [2023-07-03 17:26:46]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
int n,m,k;
const int N=5e5+100;
int f[N],c[N];
int g(int x){
    if(x==f[x]) return x;
    return f[x]=g(f[x]);
}
struct edg{
    int x,y;
}e[N];
vector<pair<int,int>>v[N];
// void dij(int )
using pa=pair<int,int>;
priority_queue<pa,vector<pa>,greater<pa>>q;
int vis[N],dis[N];
vector<int>meg[N];
int cur[N];
int main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++) cin>>c[i],c[i]--;
    for(int i=1;i<=n;i++) f[i]=i;
    for(int i=1;i<=m;i++){
        cin>>e[i].x>>e[i].y;
        auto[a,b]=e[i];
        if(g(a)==g(b)) continue;
        if(abs(c[a]-c[b])==1)f[g(a)]=b;
    }
    for(int i=1;i<=m;i++){
        // if(g(e[i].x)!+)
        auto [a,b]=e[i];
        if(g(a)==g(b)) continue;
        v[g(a)].push_back(make_pair(g(b),(c[b]-c[a]-1+k)%k));
        v[g(b)].push_back(make_pair(g(a),(c[a]-c[b]-1+k)%k));
    }
    memset(dis,63,sizeof(dis));
    int u=g(1);
    dis[u]=0;q.push(make_pair(dis[u],u));
    while(!q.empty()){
        int x=q.top().second;q.pop();
        if(vis[x]) continue;
        vis[x]=1;
        for(auto [y,w]:v[x]){
            if(dis[y]>dis[x]+w){
                dis[y]=dis[x]+w;
                q.push(make_pair(dis[y],y));
            }
        }
    }
    // for(int i=1;i<=n;i++){
        // if(g(i)==i){
            // meg[dis[i]].push_back(i);
        // }
    // }
    cerr<<"?? "<<g(3)<<" "<<g(4)<<endl;
    for(int i=1;i<=n;i++){
        cur[i]=(c[i]+1000000-dis[g(i)])%k;
    }
    for(int i=1;i<=n;i++){
        cout<<cur[i]+1<<" ";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 36244kb

input:

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

output:

1 2 3 4 

result:

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

Test #2:

score: 0
Accepted
time: 0ms
memory: 36112kb

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:

1 3 1 1 2 3 1 2 2 3 

result:

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

Test #3:

score: 0
Accepted
time: 2ms
memory: 36180kb

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:

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

result:

ok n=239, m=238, k=10

Test #4:

score: 0
Accepted
time: 1ms
memory: 36340kb

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:

89 90 91 91 92 91 92 93 92 91 92 93 94 92 95 94 91 94 93 94 90 93 90 94 91 94 92 94 91 94 92 95 93 92 91 94 94 96 96 95 93 95 95 92 94 97 94 92 92 95 92 94 90 93 93 92 96 94 93 96 97 95 95 94 96 95 97 94 92 94 95 96 93 98 95 93 97 93 96 98 93 98 96 93 94 98 94 93 91 93 93 90 96 95 97 95 91 90 92 92 ...

result:

ok n=2392, m=2391, k=100

Test #5:

score: 0
Accepted
time: 4ms
memory: 36336kb

input:

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

output:

2 3 1 2 

result:

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

Test #6:

score: 0
Accepted
time: 1ms
memory: 36384kb

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:

110 111 111 112 113 112 114 112 114 113 115 111 112 112 111 113 114 112 115 116 117 115 113 113 115 115 114 115 116 116 113 118 112 117 112 114 114 115 114 111 113 114 117 111 117 114 119 112 114 112 113 113 112 117 111 112 113 114 113 118 115 114 118 114 115 120 113 113 114 114 115 117 113 118 113 ...

result:

ok n=5000, m=4999, k=215

Test #7:

score: 0
Accepted
time: 0ms
memory: 36364kb

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:

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 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 6...

result:

ok n=5000, m=4999, k=215

Test #8:

score: 0
Accepted
time: 34ms
memory: 40256kb

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:

179 180 181 181 182 180 181 180 182 183 181 183 183 181 184 181 182 180 183 183 184 181 184 182 183 183 184 183 182 181 185 186 183 184 185 182 181 184 187 182 182 182 183 182 183 182 181 184 182 184 184 186 185 182 182 184 187 183 185 185 183 181 187 183 184 184 183 185 180 182 182 185 181 184 183 ...

result:

ok n=100000, m=99999, k=215

Test #9:

score: -100
Wrong Answer
time: 23ms
memory: 41840kb

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:

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 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 1...

result:

wrong answer Integer -194 violates the range [1, 215]