Submission #607353

# Submission time Handle Problem Language Result Execution time Memory
607353 2022-07-26T15:46:04 Z gagik_2007 Stations (IOI20_stations) C++17
100 / 100
915 ms 844 KB
#include "stations.h"
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <limits>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef ll itn;

#define ff first
#define ss second

ll n;
vector<int>g[1007];
int tin[1507], tout[1507];
int timer = 0;
vector<int>d;

void dfs(int v, int par = -1) {
	tin[v] = timer++;
	for (int i = 0; i < g[v].size(); i++) {
		int to = g[v][i];
		if (to != par) {
			dfs(to, v);
		}
	}
	tout[v] = timer++;
}

void raspr(int v, int par=-1, bool is_tin=true){
    if(is_tin){
        d.push_back(v);
    }
    for (int i = 0; i < g[v].size(); i++) {
		int to = g[v][i];
		if (to != par) {
			raspr(to, v, !is_tin);
		}
	}
	if(!is_tin){
        d.push_back(v);
	}
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	vector<int> lbl(n);
	for (int i = 0; i < n - 1; i++) {
		g[v[i]].push_back(u[i]);
		g[u[i]].push_back(v[i]);
	}
	for(int i=0;i<n;i++){
        sort(g[i].begin(),g[i].end());
	}
	raspr(0);
	int tmr=0;
	for(auto x:d){
        lbl[x]=tmr++;
	}
	for (int i = 0; i < n; i++) {
		tin[i] = 0;
		tout[i] = 0;
		timer = 0;
		g[i].clear();
	}
	d.clear();
	return lbl;
}

bool papa(int iv, int ov, int u) {
	return (iv <= u && ov >= u);
}

bool is_in(int s, vector<int> c){
    int mn=1e9;
    for(auto x:c){
        mn=min(mn,x);
    }
    return mn>=s;
}

int find_next_station(int s, int t, vector<int> c) {
	if (c.size() == 1)return c[0];
	sort(c.begin(),c.end());
	if(s==0){
        for(int i=0;i<c.size();i++){
            if(t<=c[i]){
                //cout<<c[i]<<" 1"<<endl;
                return c[i];
            }
        }
        //cout<<c[0]<<" 1"<<endl;
        return c[0];
	}
	if(is_in(s,c)){
        int is=s;
        int par=c[c.size()-1];
        int os=c[c.size()-2];
        if(!papa(is,os,t)){
            return par;
        }
        for(int i=0;i<c.size();i++){
            if(t<=c[i]){
                //cout<<c[i]<<" 1"<<endl;
                return c[i];
            }
        }
        //cout<<c[0]<<" 1"<<endl;
        return c[0];
	}
	else{
        int os=s;
        int par=c[0];
        //cout<<"par: "<<par<<endl;
        int is=c[1]-1;
        if(!papa(is,os,t)){
            return par;
        }
        for(int i=c.size()-1;i>=0;i--){
            //cout<<"ditarkel: "<<c[i]<<endl;
            if(t>=c[i]){
                //cout<<c[i]<<" 2"<<endl;
                return c[i];
            }
        }
        //cout<<c[c.size()-1]<<" 2"<<endl;
        return c[c.size()-1];
	}
}

/*
1
8 1000000
0 1
0 2
1 3
1 4
3 5
3 6
5 7
5
7 2 5
2 3 0
6 5 3
7 4 5
6 4 3
1 8 1000 0 1 0 2 1 3 1 4 3 5 3 6 5 7 5 7 2 5 2 3 0 6 5 3 7 4 5 6 4 3
1 8 1000000
0 1
0 2
1 3
1 4
2 5
2 6
3 7
5
7 2 3
1 7 3
2 5 5
0 5 2
5 0 2

1
6 1000
0 1
0 2
0 3
3 4
3 5
5
0 1 1
0 2 2
0 3 3
0 4 3
0 5 3
*/

Compilation message

stations.cpp: In function 'void dfs(int, int)':
stations.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  for (int i = 0; i < g[v].size(); i++) {
      |                  ~~^~~~~~~~~~~~~
stations.cpp: In function 'void raspr(int, int, bool)':
stations.cpp:48:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for (int i = 0; i < g[v].size(); i++) {
      |                     ~~^~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:99:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |         for(int i=0;i<c.size();i++){
      |                     ~^~~~~~~~~
stations.cpp:115:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |         for(int i=0;i<c.size();i++){
      |                     ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 493 ms 536 KB Output is correct
2 Correct 414 ms 540 KB Output is correct
3 Correct 807 ms 416 KB Output is correct
4 Correct 661 ms 420 KB Output is correct
5 Correct 610 ms 440 KB Output is correct
6 Correct 473 ms 524 KB Output is correct
7 Correct 424 ms 560 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 2 ms 508 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 421 ms 532 KB Output is correct
2 Correct 505 ms 548 KB Output is correct
3 Correct 797 ms 532 KB Output is correct
4 Correct 599 ms 536 KB Output is correct
5 Correct 547 ms 532 KB Output is correct
6 Correct 427 ms 528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 561 ms 548 KB Output is correct
2 Correct 432 ms 536 KB Output is correct
3 Correct 814 ms 544 KB Output is correct
4 Correct 629 ms 420 KB Output is correct
5 Correct 555 ms 604 KB Output is correct
6 Correct 470 ms 660 KB Output is correct
7 Correct 433 ms 548 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 573 ms 728 KB Output is correct
12 Correct 352 ms 648 KB Output is correct
13 Correct 447 ms 676 KB Output is correct
14 Correct 431 ms 532 KB Output is correct
15 Correct 50 ms 620 KB Output is correct
16 Correct 62 ms 676 KB Output is correct
17 Correct 88 ms 816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 804 ms 420 KB Output is correct
2 Correct 717 ms 420 KB Output is correct
3 Correct 519 ms 528 KB Output is correct
4 Correct 1 ms 500 KB Output is correct
5 Correct 5 ms 492 KB Output is correct
6 Correct 1 ms 540 KB Output is correct
7 Correct 581 ms 416 KB Output is correct
8 Correct 915 ms 532 KB Output is correct
9 Correct 630 ms 420 KB Output is correct
10 Correct 580 ms 536 KB Output is correct
11 Correct 6 ms 500 KB Output is correct
12 Correct 4 ms 492 KB Output is correct
13 Correct 3 ms 492 KB Output is correct
14 Correct 4 ms 500 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 522 ms 536 KB Output is correct
17 Correct 507 ms 532 KB Output is correct
18 Correct 356 ms 420 KB Output is correct
19 Correct 483 ms 420 KB Output is correct
20 Correct 518 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 557 ms 548 KB Output is correct
2 Correct 432 ms 528 KB Output is correct
3 Correct 760 ms 444 KB Output is correct
4 Correct 623 ms 416 KB Output is correct
5 Correct 452 ms 532 KB Output is correct
6 Correct 446 ms 528 KB Output is correct
7 Correct 432 ms 540 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 3 ms 620 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
11 Correct 416 ms 524 KB Output is correct
12 Correct 512 ms 576 KB Output is correct
13 Correct 900 ms 420 KB Output is correct
14 Correct 610 ms 416 KB Output is correct
15 Correct 557 ms 536 KB Output is correct
16 Correct 443 ms 548 KB Output is correct
17 Correct 426 ms 540 KB Output is correct
18 Correct 425 ms 760 KB Output is correct
19 Correct 428 ms 780 KB Output is correct
20 Correct 469 ms 532 KB Output is correct
21 Correct 41 ms 620 KB Output is correct
22 Correct 74 ms 688 KB Output is correct
23 Correct 104 ms 672 KB Output is correct
24 Correct 4 ms 500 KB Output is correct
25 Correct 5 ms 500 KB Output is correct
26 Correct 3 ms 496 KB Output is correct
27 Correct 3 ms 492 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 520 ms 416 KB Output is correct
30 Correct 521 ms 532 KB Output is correct
31 Correct 482 ms 544 KB Output is correct
32 Correct 485 ms 420 KB Output is correct
33 Correct 561 ms 540 KB Output is correct
34 Correct 316 ms 528 KB Output is correct
35 Correct 436 ms 772 KB Output is correct
36 Correct 446 ms 648 KB Output is correct
37 Correct 417 ms 664 KB Output is correct
38 Correct 471 ms 664 KB Output is correct
39 Correct 425 ms 636 KB Output is correct
40 Correct 411 ms 760 KB Output is correct
41 Correct 479 ms 640 KB Output is correct
42 Correct 63 ms 676 KB Output is correct
43 Correct 97 ms 664 KB Output is correct
44 Correct 129 ms 624 KB Output is correct
45 Correct 177 ms 544 KB Output is correct
46 Correct 311 ms 544 KB Output is correct
47 Correct 255 ms 528 KB Output is correct
48 Correct 60 ms 728 KB Output is correct
49 Correct 52 ms 844 KB Output is correct