#include <bits/stdc++.h>
using namespace std;
int const N=1005;
vector<int> adj[N];
int tim=-1;
int in[N],out[N];
int lab[N];
void dfs(int node,int par=-1){
tim++;
in[node]=tim;
for(int i:adj[node])
if(i!=par)
dfs(i,node);
out[node]=tim;
}
vector<int> solver(int n){
for(int i=0;i<n;i++)
if(adj[i].size()==1){
dfs(i);
break;
}
vector<int> val;
for (int i = 0; i < n; ++i)
val.push_back(in[i]);
return val;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v){
for (int i = 0; i < n; ++i)
{
adj[i].clear();
tim=-1;
in[i]=out[i]=0;
}
for (int i = 0; i < n-1; ++i)
{
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
if(k<=1000)
return solver(n);
dfs(0);
vector<int> val;
for (int i = 0; i < n; ++i)
val.push_back((in[i]*1000)+out[i]);
// for(int i=0;i<n;i++)
// cout<<val[i]<<' ';
// cout<<endl;
return val;
}
int fns(int s,int t,vector<int> c){
if(c.size()==1)
return c[0];
if(c[0]>c[1])
swap(c[0],c[1]);
if(t<=c[0])
return c[0];
return c[1];
}
int find_next_station(int s, int t, vector<int> c){
bool b=(s>1000 || t>1000);
for(int i=0;i<c.size();i++)
if(c[i]>1000)
b=1;
if(b==0)
return fns(s,t,c);
// cout<<s<<' '<<t<<endl;
int n=c.size();
int inn[n],outt[n];
int ti=t/1000,to=t%1000;
for (int i = 0; i < n; ++i)
{
inn[i]=c[i]/1000;
outt[i]=c[i]%1000;
}
int si=s/1000,so=s%1000;
for(int i=0;i<n;i++)
if(inn[i]<=ti && to<=outt[i] && !(inn[i]<=si && so<=outt[i]))
return c[i];
for(int i=0;i<n;i++)
if(inn[i]<=si && so<=outt[i])
return c[i];
return 0;
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:62:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int i=0;i<c.size();i++)
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
402 ms |
684 KB |
Output is correct |
2 |
Correct |
334 ms |
684 KB |
Output is correct |
3 |
Correct |
633 ms |
684 KB |
Output is correct |
4 |
Correct |
466 ms |
684 KB |
Output is correct |
5 |
Correct |
413 ms |
684 KB |
Output is correct |
6 |
Correct |
315 ms |
684 KB |
Output is correct |
7 |
Correct |
324 ms |
684 KB |
Output is correct |
8 |
Correct |
2 ms |
764 KB |
Output is correct |
9 |
Correct |
3 ms |
764 KB |
Output is correct |
10 |
Correct |
1 ms |
772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
349 ms |
688 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
368 ms |
684 KB |
Output is correct |
2 |
Correct |
341 ms |
684 KB |
Output is correct |
3 |
Correct |
624 ms |
796 KB |
Output is correct |
4 |
Correct |
478 ms |
684 KB |
Output is correct |
5 |
Correct |
414 ms |
684 KB |
Output is correct |
6 |
Correct |
275 ms |
896 KB |
Output is correct |
7 |
Correct |
310 ms |
940 KB |
Output is correct |
8 |
Correct |
2 ms |
768 KB |
Output is correct |
9 |
Correct |
3 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
11 |
Correct |
403 ms |
684 KB |
Output is correct |
12 |
Correct |
335 ms |
792 KB |
Output is correct |
13 |
Correct |
310 ms |
788 KB |
Output is correct |
14 |
Correct |
289 ms |
684 KB |
Output is correct |
15 |
Correct |
40 ms |
716 KB |
Output is correct |
16 |
Correct |
53 ms |
736 KB |
Output is correct |
17 |
Correct |
76 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
591 ms |
696 KB |
Output is correct |
2 |
Correct |
462 ms |
684 KB |
Output is correct |
3 |
Correct |
424 ms |
684 KB |
Output is correct |
4 |
Correct |
2 ms |
768 KB |
Output is correct |
5 |
Correct |
4 ms |
764 KB |
Output is correct |
6 |
Correct |
1 ms |
948 KB |
Output is correct |
7 |
Correct |
445 ms |
684 KB |
Output is correct |
8 |
Correct |
536 ms |
684 KB |
Output is correct |
9 |
Correct |
463 ms |
684 KB |
Output is correct |
10 |
Correct |
410 ms |
684 KB |
Output is correct |
11 |
Correct |
2 ms |
768 KB |
Output is correct |
12 |
Correct |
3 ms |
768 KB |
Output is correct |
13 |
Correct |
4 ms |
768 KB |
Output is correct |
14 |
Correct |
3 ms |
776 KB |
Output is correct |
15 |
Correct |
1 ms |
768 KB |
Output is correct |
16 |
Correct |
354 ms |
684 KB |
Output is correct |
17 |
Correct |
368 ms |
680 KB |
Output is correct |
18 |
Correct |
341 ms |
684 KB |
Output is correct |
19 |
Correct |
353 ms |
684 KB |
Output is correct |
20 |
Correct |
376 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
390 ms |
936 KB |
Partially correct |
2 |
Partially correct |
332 ms |
908 KB |
Partially correct |
3 |
Partially correct |
639 ms |
684 KB |
Partially correct |
4 |
Partially correct |
423 ms |
796 KB |
Partially correct |
5 |
Partially correct |
382 ms |
684 KB |
Partially correct |
6 |
Partially correct |
314 ms |
684 KB |
Partially correct |
7 |
Partially correct |
309 ms |
788 KB |
Partially correct |
8 |
Partially correct |
2 ms |
764 KB |
Partially correct |
9 |
Partially correct |
2 ms |
768 KB |
Partially correct |
10 |
Partially correct |
0 ms |
768 KB |
Partially correct |
11 |
Partially correct |
307 ms |
688 KB |
Partially correct |
12 |
Partially correct |
362 ms |
684 KB |
Partially correct |
13 |
Partially correct |
653 ms |
684 KB |
Partially correct |
14 |
Partially correct |
414 ms |
684 KB |
Partially correct |
15 |
Partially correct |
460 ms |
684 KB |
Partially correct |
16 |
Partially correct |
325 ms |
684 KB |
Partially correct |
17 |
Partially correct |
387 ms |
684 KB |
Partially correct |
18 |
Partially correct |
325 ms |
792 KB |
Partially correct |
19 |
Partially correct |
314 ms |
784 KB |
Partially correct |
20 |
Partially correct |
329 ms |
684 KB |
Partially correct |
21 |
Partially correct |
27 ms |
764 KB |
Partially correct |
22 |
Partially correct |
49 ms |
764 KB |
Partially correct |
23 |
Partially correct |
63 ms |
716 KB |
Partially correct |
24 |
Partially correct |
2 ms |
804 KB |
Partially correct |
25 |
Partially correct |
3 ms |
776 KB |
Partially correct |
26 |
Partially correct |
3 ms |
768 KB |
Partially correct |
27 |
Partially correct |
1 ms |
768 KB |
Partially correct |
28 |
Partially correct |
1 ms |
768 KB |
Partially correct |
29 |
Partially correct |
345 ms |
804 KB |
Partially correct |
30 |
Partially correct |
340 ms |
684 KB |
Partially correct |
31 |
Partially correct |
357 ms |
684 KB |
Partially correct |
32 |
Partially correct |
350 ms |
680 KB |
Partially correct |
33 |
Partially correct |
366 ms |
696 KB |
Partially correct |
34 |
Partially correct |
222 ms |
936 KB |
Partially correct |
35 |
Partially correct |
265 ms |
684 KB |
Partially correct |
36 |
Partially correct |
261 ms |
940 KB |
Partially correct |
37 |
Partially correct |
315 ms |
792 KB |
Partially correct |
38 |
Partially correct |
321 ms |
792 KB |
Partially correct |
39 |
Partially correct |
312 ms |
808 KB |
Partially correct |
40 |
Partially correct |
291 ms |
936 KB |
Partially correct |
41 |
Partially correct |
324 ms |
1556 KB |
Partially correct |
42 |
Partially correct |
33 ms |
1020 KB |
Partially correct |
43 |
Partially correct |
60 ms |
688 KB |
Partially correct |
44 |
Partially correct |
88 ms |
716 KB |
Partially correct |
45 |
Partially correct |
98 ms |
684 KB |
Partially correct |
46 |
Partially correct |
216 ms |
684 KB |
Partially correct |
47 |
Partially correct |
207 ms |
684 KB |
Partially correct |
48 |
Partially correct |
36 ms |
892 KB |
Partially correct |
49 |
Partially correct |
31 ms |
880 KB |
Partially correct |