Submission #838304

# Submission time Handle Problem Language Result Execution time Memory
838304 2023-08-26T13:59:10 Z JakobZorz Stations (IOI20_stations) C++14
100 / 100
737 ms 780 KB
#include"stations.h"
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;

vector<int>labels;
int n;
vector<int>nodes[1000];
int curr_label;

void dfs(int node,int par,bool pr){
    if(pr)
        labels[node]=curr_label++;
    for(int ne:nodes[node]){
        if(ne==par)
            continue;
        dfs(ne,node,!pr);
    }
    if(!pr)
        labels[node]=curr_label++;
}

vector<int>label(int N,int k,vector<int>u,vector<int>v){
    n=N;
    labels.resize(n);
    for(int i=0;i<n;i++)
        nodes[i].clear();
    curr_label=0;
    for(int i=0;i<n-1;i++){
        nodes[u[i]].push_back(v[i]);
        nodes[v[i]].push_back(u[i]);
    }
    
    dfs(0,0,false);
	
	return labels;
}

int find_next_station(int s,int t,vector<int>c){
    sort(c.begin(),c.end());
    /*cout<<"s "<<s<<endl;
    cout<<"t "<<t<<endl;
    cout<<"arr ";
    for(int i:c)
        cout<<i<<" ";
    cout<<endl;*/
    
    if(c.size()==1)
        return c[0];
    
    if(s<c[0]){
        // s is smaller that everyhting on its subtree
        if(t<s||t>c.back()) // target is not in subtree
            return c.back(); // the biggest is the root then
        
        // it must be in one of the children
        for(int i=0;i<(int)c.size()-1;i++){
            if(c[i]<t&&t<=c[i+1])
                return c[i+1];
        }
        
        return c[0];
    }else{
        // s is bigger that everything on its subtree
        
        if(t>s||t<c[0]) // target is not in subtree
            return c[0]; // the biggest is the root then
        
        // it must be in one of the children
        for(int i=0;i<(int)c.size()-1;i++){
            if(c[i]<=t&&t<c[i+1])
                return c[i];
        }
        
        return c.back();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 388 ms 660 KB Output is correct
2 Correct 401 ms 652 KB Output is correct
3 Correct 581 ms 420 KB Output is correct
4 Correct 417 ms 528 KB Output is correct
5 Correct 416 ms 528 KB Output is correct
6 Correct 391 ms 652 KB Output is correct
7 Correct 361 ms 552 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 1 ms 500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 375 ms 532 KB Output is correct
2 Correct 373 ms 548 KB Output is correct
3 Correct 727 ms 420 KB Output is correct
4 Correct 469 ms 548 KB Output is correct
5 Correct 401 ms 420 KB Output is correct
6 Correct 348 ms 548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 438 ms 676 KB Output is correct
2 Correct 418 ms 656 KB Output is correct
3 Correct 737 ms 416 KB Output is correct
4 Correct 459 ms 420 KB Output is correct
5 Correct 514 ms 416 KB Output is correct
6 Correct 339 ms 672 KB Output is correct
7 Correct 291 ms 544 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
11 Correct 406 ms 416 KB Output is correct
12 Correct 421 ms 780 KB Output is correct
13 Correct 364 ms 648 KB Output is correct
14 Correct 348 ms 544 KB Output is correct
15 Correct 38 ms 620 KB Output is correct
16 Correct 55 ms 572 KB Output is correct
17 Correct 91 ms 548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 585 ms 416 KB Output is correct
2 Correct 385 ms 548 KB Output is correct
3 Correct 460 ms 416 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 4 ms 496 KB Output is correct
6 Correct 0 ms 492 KB Output is correct
7 Correct 389 ms 524 KB Output is correct
8 Correct 606 ms 532 KB Output is correct
9 Correct 475 ms 416 KB Output is correct
10 Correct 486 ms 416 KB Output is correct
11 Correct 2 ms 500 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 500 KB Output is correct
15 Correct 1 ms 496 KB Output is correct
16 Correct 359 ms 416 KB Output is correct
17 Correct 392 ms 416 KB Output is correct
18 Correct 381 ms 416 KB Output is correct
19 Correct 393 ms 420 KB Output is correct
20 Correct 405 ms 416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 419 ms 676 KB Output is correct
2 Correct 306 ms 548 KB Output is correct
3 Correct 574 ms 420 KB Output is correct
4 Correct 484 ms 416 KB Output is correct
5 Correct 547 ms 420 KB Output is correct
6 Correct 407 ms 548 KB Output is correct
7 Correct 406 ms 548 KB Output is correct
8 Correct 2 ms 524 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 0 ms 500 KB Output is correct
11 Correct 365 ms 588 KB Output is correct
12 Correct 414 ms 672 KB Output is correct
13 Correct 735 ms 536 KB Output is correct
14 Correct 489 ms 416 KB Output is correct
15 Correct 389 ms 420 KB Output is correct
16 Correct 337 ms 544 KB Output is correct
17 Correct 366 ms 528 KB Output is correct
18 Correct 336 ms 644 KB Output is correct
19 Correct 298 ms 772 KB Output is correct
20 Correct 301 ms 532 KB Output is correct
21 Correct 46 ms 620 KB Output is correct
22 Correct 45 ms 572 KB Output is correct
23 Correct 80 ms 544 KB Output is correct
24 Correct 2 ms 488 KB Output is correct
25 Correct 4 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 0 ms 500 KB Output is correct
29 Correct 317 ms 420 KB Output is correct
30 Correct 354 ms 524 KB Output is correct
31 Correct 302 ms 416 KB Output is correct
32 Correct 362 ms 532 KB Output is correct
33 Correct 333 ms 416 KB Output is correct
34 Correct 230 ms 660 KB Output is correct
35 Correct 273 ms 676 KB Output is correct
36 Correct 329 ms 760 KB Output is correct
37 Correct 382 ms 620 KB Output is correct
38 Correct 379 ms 708 KB Output is correct
39 Correct 298 ms 660 KB Output is correct
40 Correct 347 ms 652 KB Output is correct
41 Correct 367 ms 760 KB Output is correct
42 Correct 45 ms 572 KB Output is correct
43 Correct 69 ms 544 KB Output is correct
44 Correct 106 ms 644 KB Output is correct
45 Correct 138 ms 628 KB Output is correct
46 Correct 248 ms 612 KB Output is correct
47 Correct 254 ms 548 KB Output is correct
48 Correct 44 ms 672 KB Output is correct
49 Correct 34 ms 688 KB Output is correct