#include<bits/stdc++.h>
#include "stations.h"
#define ll long long
using namespace std;
ll N,K,parnost[1005],in[1005],out[1005],vrem=0;
vector<ll> stablo[1005];
vector<int> L;
void dfs(ll gde,ll pret,int par=0){
in[gde]=++vrem;
parnost[gde]=par;
for(int i=0;i<stablo[gde].size();i++)
if(stablo[gde][i]!=pret)
dfs(stablo[gde][i],gde,par^1);
out[gde]=++vrem;
return;
}
struct slog{
int id,sv,nv;
} niz[1005];
bool pov(slog a,slog b){
return a.sv<b.sv;
}
bool poid(slog a,slog b){
return a.id<b.id;
}
vector<int> label(int n,int k,vector<int> u,vector<int> v){
N=n;
K=k;
for(ll i=0;i<N;i++)
stablo[i].clear();
for(ll i=0;i<N-1;i++){
stablo[u[i]].push_back(v[i]);
stablo[v[i]].push_back(u[i]);
}
vrem=0;
dfs(0,0);
for(int i=0;i<N;i++){
in[i]--;
out[i]--;
}
L.clear();
//cout<<"LABELE"<<endl;
for(ll i=0;i<N;i++){
niz[i].id=i;
if(parnost[i]==0)
niz[i].sv=in[i];
else
niz[i].sv=out[i];
// cout<<i<<" "<<L[i]<<endl;
}
sort(niz,niz+N,pov);
for(int i=0;i<N;i++)
niz[i].nv=i;
sort(niz,niz+N,poid);
for(int i=0;i<N;i++)
L.push_back(niz[i].nv);
return L;
}
int find_next_station(int s,int t,vector<int> c){
if(c.size()==1)
return c[0];
for(int i=0;i<c.size();i++)
if(c[i]==t)
return c[i];
bool jein=true;
for(int i=0;i<c.size();i++)
if(c[i]<s)
jein=false;
sort(c.begin(),c.end());
if(jein){///IN cvor
if(t<s)
return c[c.size()-1];
for(int i=0;i<c.size();i++)
if(c[i]>=t)
return c[i];
return c[c.size()-1];
}
///Out cvor
if(t>s)
return c[0];
for(int i=1;i<c.size();i++)
if(t<c[i])
return c[i-1];
return c[c.size()-1];
}
Compilation message
stations.cpp: In function 'void dfs(long long int, long long int, int)':
stations.cpp:11:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | for(int i=0;i<stablo[gde].size();i++)
| ~^~~~~~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:63:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int i=0;i<c.size();i++)
| ~^~~~~~~~~
stations.cpp:67:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int i=0;i<c.size();i++)
| ~^~~~~~~~~
stations.cpp:74:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(int i=0;i<c.size();i++)
| ~^~~~~~~~~
stations.cpp:82:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for(int i=1;i<c.size();i++)
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
515 ms |
676 KB |
Output is correct |
2 |
Correct |
420 ms |
652 KB |
Output is correct |
3 |
Correct |
805 ms |
512 KB |
Output is correct |
4 |
Correct |
597 ms |
528 KB |
Output is correct |
5 |
Correct |
541 ms |
536 KB |
Output is correct |
6 |
Correct |
436 ms |
652 KB |
Output is correct |
7 |
Correct |
396 ms |
536 KB |
Output is correct |
8 |
Correct |
2 ms |
628 KB |
Output is correct |
9 |
Correct |
4 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
416 ms |
544 KB |
Output is correct |
2 |
Correct |
448 ms |
544 KB |
Output is correct |
3 |
Correct |
761 ms |
548 KB |
Output is correct |
4 |
Correct |
583 ms |
548 KB |
Output is correct |
5 |
Correct |
526 ms |
524 KB |
Output is correct |
6 |
Correct |
392 ms |
548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
476 ms |
704 KB |
Output is correct |
2 |
Correct |
415 ms |
804 KB |
Output is correct |
3 |
Correct |
918 ms |
656 KB |
Output is correct |
4 |
Correct |
696 ms |
544 KB |
Output is correct |
5 |
Correct |
526 ms |
532 KB |
Output is correct |
6 |
Correct |
453 ms |
784 KB |
Output is correct |
7 |
Correct |
469 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
628 KB |
Output is correct |
9 |
Correct |
3 ms |
744 KB |
Output is correct |
10 |
Correct |
2 ms |
620 KB |
Output is correct |
11 |
Correct |
513 ms |
548 KB |
Output is correct |
12 |
Correct |
437 ms |
772 KB |
Output is correct |
13 |
Correct |
477 ms |
792 KB |
Output is correct |
14 |
Correct |
418 ms |
548 KB |
Output is correct |
15 |
Correct |
49 ms |
620 KB |
Output is correct |
16 |
Correct |
56 ms |
672 KB |
Output is correct |
17 |
Correct |
112 ms |
676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
831 ms |
532 KB |
Output is correct |
2 |
Correct |
589 ms |
532 KB |
Output is correct |
3 |
Correct |
624 ms |
544 KB |
Output is correct |
4 |
Correct |
1 ms |
620 KB |
Output is correct |
5 |
Correct |
4 ms |
620 KB |
Output is correct |
6 |
Correct |
2 ms |
616 KB |
Output is correct |
7 |
Correct |
579 ms |
672 KB |
Output is correct |
8 |
Correct |
871 ms |
544 KB |
Output is correct |
9 |
Correct |
633 ms |
672 KB |
Output is correct |
10 |
Correct |
440 ms |
532 KB |
Output is correct |
11 |
Correct |
3 ms |
744 KB |
Output is correct |
12 |
Correct |
5 ms |
620 KB |
Output is correct |
13 |
Correct |
4 ms |
628 KB |
Output is correct |
14 |
Correct |
4 ms |
620 KB |
Output is correct |
15 |
Correct |
1 ms |
628 KB |
Output is correct |
16 |
Correct |
544 ms |
528 KB |
Output is correct |
17 |
Correct |
478 ms |
544 KB |
Output is correct |
18 |
Correct |
527 ms |
532 KB |
Output is correct |
19 |
Correct |
500 ms |
672 KB |
Output is correct |
20 |
Correct |
449 ms |
664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
486 ms |
788 KB |
Output is correct |
2 |
Correct |
475 ms |
672 KB |
Output is correct |
3 |
Correct |
966 ms |
544 KB |
Output is correct |
4 |
Correct |
593 ms |
660 KB |
Output is correct |
5 |
Correct |
543 ms |
544 KB |
Output is correct |
6 |
Correct |
392 ms |
672 KB |
Output is correct |
7 |
Correct |
426 ms |
660 KB |
Output is correct |
8 |
Correct |
3 ms |
620 KB |
Output is correct |
9 |
Correct |
5 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
628 KB |
Output is correct |
11 |
Correct |
423 ms |
540 KB |
Output is correct |
12 |
Correct |
555 ms |
544 KB |
Output is correct |
13 |
Correct |
857 ms |
544 KB |
Output is correct |
14 |
Correct |
637 ms |
672 KB |
Output is correct |
15 |
Correct |
537 ms |
532 KB |
Output is correct |
16 |
Correct |
439 ms |
676 KB |
Output is correct |
17 |
Correct |
531 ms |
656 KB |
Output is correct |
18 |
Correct |
446 ms |
788 KB |
Output is correct |
19 |
Correct |
444 ms |
796 KB |
Output is correct |
20 |
Correct |
397 ms |
544 KB |
Output is correct |
21 |
Correct |
71 ms |
548 KB |
Output is correct |
22 |
Correct |
60 ms |
748 KB |
Output is correct |
23 |
Correct |
112 ms |
700 KB |
Output is correct |
24 |
Correct |
4 ms |
628 KB |
Output is correct |
25 |
Correct |
3 ms |
620 KB |
Output is correct |
26 |
Correct |
4 ms |
620 KB |
Output is correct |
27 |
Correct |
3 ms |
620 KB |
Output is correct |
28 |
Correct |
1 ms |
620 KB |
Output is correct |
29 |
Correct |
556 ms |
580 KB |
Output is correct |
30 |
Correct |
427 ms |
548 KB |
Output is correct |
31 |
Correct |
484 ms |
544 KB |
Output is correct |
32 |
Correct |
503 ms |
548 KB |
Output is correct |
33 |
Correct |
566 ms |
660 KB |
Output is correct |
34 |
Correct |
329 ms |
676 KB |
Output is correct |
35 |
Correct |
439 ms |
788 KB |
Output is correct |
36 |
Correct |
406 ms |
788 KB |
Output is correct |
37 |
Correct |
405 ms |
788 KB |
Output is correct |
38 |
Correct |
431 ms |
792 KB |
Output is correct |
39 |
Correct |
401 ms |
760 KB |
Output is correct |
40 |
Correct |
394 ms |
788 KB |
Output is correct |
41 |
Correct |
421 ms |
792 KB |
Output is correct |
42 |
Correct |
62 ms |
700 KB |
Output is correct |
43 |
Correct |
114 ms |
680 KB |
Output is correct |
44 |
Correct |
130 ms |
676 KB |
Output is correct |
45 |
Correct |
158 ms |
652 KB |
Output is correct |
46 |
Correct |
285 ms |
536 KB |
Output is correct |
47 |
Correct |
273 ms |
544 KB |
Output is correct |
48 |
Correct |
47 ms |
840 KB |
Output is correct |
49 |
Correct |
62 ms |
804 KB |
Output is correct |