UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214139#2680. Travela_sad_soul0991ms2436kbC++111.4kb2024-11-15 19:44:412024-11-15 23:25:06

answer

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+10;
struct node{
    int to;
    int nxt;
    int cst;
}e[MAXN];;
int tot,head[MAXN];
void add(int u,int v,int cst){
    e[++tot].to=v;e[tot].nxt=head[u];e[tot].cst=cst;head[u]=tot;
}
int f[500][500];
int cnt[500];
bool vis[500];
struct arr{
    int u,o,x;
    bool operator<(const arr X)const {
        if(x==X.x)return o>X.o;
        return x<X.x;
    }
};
int n,m,L;
void dijst(int s){
    priority_queue<arr>q;
    memset(cnt,0,sizeof(cnt));
    q.push(arr{s,L,0});
    cnt[s]=0;
    while(!q.empty()){
        int u=q.top().u,oil=q.top().o,x=q.top().x;q.pop();
        f[s][u]=min(f[s][u],x);
        ++cnt[s];
        if(cnt[s]>n)break;
        for(int i=head[u];i;i=e[i].nxt){
            int v=e[i].to;
            if(f[s][u]>f[s][v])continue;
            if(e[i].cst>L)continue;
            if(oil>=e[i].cst){
                q.push(arr{v,oil-e[i].cst,x});
            }else {
                q.push(arr{v,L,x+1});
            }
        }
    }
}
int main(){
    memset(f,63,sizeof(f));
    scanf("%d%d%d",&n,&m,&L);
    for(int i=1;i<=m;++i){
        int u,v,l;scanf("%d%d%d",&u,&v,&l);
        add(u,v,l),add(v,u,l);
    }
    for(int i=1;i<=n;++i)dijst(i);
    int q;scanf("%d",&q);
    while (q--){
        int s,t;scanf("%d%d",&s,&t);
        if(f[s][t]>1e7)puts("-1");
        else printf("%d\n",f[s][t]);
    }
    
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 0
Wrong Answer
time: 39ms
memory: 2344kb

input:

300 1031 1000000000
277 94 1000000000
245 178 1000000000
161 263 1000000000
187 73 1000000000
219 36...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

wrong answer 1st lines differ - expected: '3', found: '-1'

Test #2:

score: 0
Wrong Answer
time: 33ms
memory: 2292kb

input:

300 604 1000000000
216 182 1000000000
171 212 1000000000
201 242 1000000000
181 93 1000000000
181 23...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

wrong answer 1st lines differ - expected: '2', found: '-1'

Test #3:

score: 0
Wrong Answer
time: 35ms
memory: 2332kb

input:

300 887 1000000000
74 50 1000000000
111 160 1000000000
27 44 1000000000
171 145 1000000000
202 223 1...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

wrong answer 1st lines differ - expected: '3', found: '-1'

Test #4:

score: 0
Wrong Answer
time: 46ms
memory: 2352kb

input:

300 1216 1000000000
272 88 1000000000
186 264 1000000000
132 72 1000000000
203 142 1000000000
126 79...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

wrong answer 1st lines differ - expected: '3', found: '-1'

Test #5:

score: 0
Wrong Answer
time: 42ms
memory: 2392kb

input:

300 1361 1000000000
65 156 1000000000
214 24 1000000000
217 129 1000000000
197 235 1000000000
154 17...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

wrong answer 1st lines differ - expected: '1', found: '-1'

Test #6:

score: 0
Wrong Answer
time: 24ms
memory: 2280kb

input:

300 294 1000000000
167 15 1000000000
21 161 1000000000
250 37 1000000000
32 169 1000000000
60 194 10...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

wrong answer 6th lines differ - expected: '10', found: '-1'

Test #7:

score: 0
Wrong Answer
time: 47ms
memory: 2388kb

input:

300 1415 1000000000
215 261 1000000000
208 170 1000000000
191 189 1000000000
103 293 1000000000
215 ...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1...

result:

wrong answer 1st lines differ - expected: '2', found: '-1'

Test #8:

score: 0
Wrong Answer
time: 56ms
memory: 2404kb

input:

300 1851 1000000000
75 233 1000000000
285 187 1000000000
269 89 1000000000
245 240 1000000000
134 15...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

wrong answer 1st lines differ - expected: '2', found: '-1'

Test #9:

score: 0
Wrong Answer
time: 90ms
memory: 2436kb

input:

300 3491 1000000000
50 182 915397053
64 2 856684642
9 95 764580683
243 83 861656918
89 150 957931575...

output:

-1
-1
-1
-1
3
-1
-1
-1
-1
-1
-1
7
-1
-1
-1
-1
-1
-1
3
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

wrong answer 1st lines differ - expected: '0', found: '-1'

Test #10:

score: 0
Wrong Answer
time: 47ms
memory: 2404kb

input:

300 1945 1000000000
47 188 533599055
65 169 659762016
227 218 566867001
31 6 774365594
122 236 88888...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
4
-1
32
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
14
9
-1
-1
-1
-1
-1
-1
11
-1
...

result:

wrong answer 1st lines differ - expected: '1', found: '-1'

Test #11:

score: 0
Wrong Answer
time: 60ms
memory: 2416kb

input:

300 2334 1000000000
26 91 919619085
219 184 684076993
140 146 629398252
290 115 620714562
183 200 73...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
5
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
6
-1
-1
-1
-1
...

result:

wrong answer 1st lines differ - expected: '1', found: '-1'

Test #12:

score: 0
Wrong Answer
time: 53ms
memory: 2396kb

input:

300 1783 1000000000
125 59 913425325
201 103 599015877
260 43 836109177
295 13 548588010
289 12 8800...

output:

-1
-1
-1
-1
-1
-1
-1
9
-1
-1
-1
-1
-1
-1
-1
12
-1
-1
-1
-1
-1
-1
-1
-1
-1
6
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

wrong answer 1st lines differ - expected: '2', found: '-1'

Test #13:

score: 0
Wrong Answer
time: 71ms
memory: 2420kb

input:

300 2716 1000000000
53 190 602802421
18 208 539008167
159 74 737081869
54 107 984931630
147 117 5946...

output:

35
-1
-1
22
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
36
-1
-1
-1
-1
-1
10
29
24
-1
-1
43
33
-1
-...

result:

wrong answer 1st lines differ - expected: '1', found: '35'

Test #14:

score: 0
Wrong Answer
time: 54ms
memory: 2400kb

input:

300 1714 1000000000
120 169 762488498
47 114 721913063
256 146 933043076
109 115 853379190
2 119 623...

output:

-1
-1
-1
29
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
5
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1...

result:

wrong answer 1st lines differ - expected: '1', found: '-1'

Test #15:

score: 0
Wrong Answer
time: 47ms
memory: 2348kb

input:

300 1363 1000000000
112 73 623162757
258 123 797794754
132 144 698032064
177 36 915826033
199 297 92...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
7
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1...

result:

wrong answer 1st lines differ - expected: '2', found: '-1'

Test #16:

score: 0
Wrong Answer
time: 78ms
memory: 2432kb

input:

300 3272 1000000000
138 129 925006622
105 6 708584786
254 96 692737494
293 82 747671739
31 126 53260...

output:

-1
-1
-1
-1
35
10
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

wrong answer 1st lines differ - expected: '1', found: '-1'

Test #17:

score: 0
Wrong Answer
time: 67ms
memory: 2412kb

input:

300 2173 1000000000
100 231 976052116
281 144 956967155
125 74 633252239
9 129 530570874
206 99 5197...

output:

2
-1
-1
7
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
17
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

wrong answer 2nd lines differ - expected: '1', found: '-1'

Test #18:

score: 0
Wrong Answer
time: 25ms
memory: 2288kb

input:

300 435 1000000000
54 113 781774474
276 245 753387176
241 210 611204276
49 27 664064527
261 106 8293...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

wrong answer 1st lines differ - expected: '5', found: '-1'

Test #19:

score: 0
Wrong Answer
time: 42ms
memory: 2352kb

input:

300 1226 1000000000
63 220 854868106
174 159 653590287
197 51 532677187
185 108 804016280
284 147 75...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

wrong answer 1st lines differ - expected: '2', found: '-1'

Test #20:

score: 0
Wrong Answer
time: 35ms
memory: 2324kb

input:

300 787 1000000000
285 266 813321760
289 201 623167413
7 76 867785258
155 164 621115697
109 226 5419...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1...

result:

wrong answer 1st lines differ - expected: '3', found: '-1'