Submission #415631

# Submission time Handle Problem Language Result Execution time Memory
415631 2021-06-01T09:55:37 Z MKopchev Stations (IOI20_stations) C++14
76 / 100
1246 ms 828 KB
#include "stations.h"
#include<bits/stdc++.h>
using namespace std;

const int nmax=1e3+42;

vector<int> adj[nmax];

int in[nmax],out[nmax],when;

vector<int> outp;

void dfs(int node,int par,int depth)
{
    when++;

    in[node]=when;

    for(auto w:adj[node])
        if(w!=par)dfs(w,node,depth+1);

    when++;

    out[node]=when;

    //cout<<node<<" "<<depth<<" -> "<<in[node]<<" "<<out[node]<<endl;

    if(depth%2==0)outp[node]=in[node];
    else outp[node]=out[node];
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	outp={};
	for(int i=0;i<n;i++)adj[i]={},outp.push_back(0);
	when=0;

	for(int i=0;i<n-1;i++)
    {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }

	dfs(0,0,0);

	//for(auto w:outp)cout<<w<<" ";cout<<endl;

	return outp;
}

int find_next_station(int s, int t, std::vector<int> c) {

	for(auto w:c)
        if(w==t)return w;

    sort(c.begin(),c.end());

    if(c.size()==1)return c[0];

    //cout<<"s= "<<s<<" t= "<<t<<" c= ";for(auto w:c)cout<<w<<" ";cout<<endl;

	if(s<c[0])
    {
        vector<int> c_in={s+1};
        vector<int> c_out=c;

        c_out.pop_back();

        for(int i=1;i<c_out.size();i++)
            c_in.push_back(c_out[i-1]+1);

        for(int i=0;i<c_in.size();i++)
            if(c_in[i]<=t&&t<=c_out[i])return c[i];

        return c.back();
    }
        vector<int> c_in=c;
        vector<int> c_out={};

        c_in.erase(c_in.begin(),c_in.begin()+1);

        for(int i=0;i+1<c_in.size();i++)
            c_out.push_back(c_in[i+1]-1);

        c_out.push_back(s-1);

        /*
        cout<<"c_in: ";for(auto w:c_in)cout<<w<<" ";cout<<endl;
        cout<<"c_out: ";for(auto w:c_out)cout<<w<<" ";cout<<endl;
        */

        for(int i=0;i<c_in.size();i++)
            if(c_in[i]<=t&&t<=c_out[i])return c[i+1];

        return c[0];
}
/*
static int max_label = 0;
static int r, n, k, q;
static std::vector<int> u, v, labels, answers;
static std::map<int, int> reverse_labels;
static std::vector<std::vector<int>> adjlist;
static int s, t, w;
static std::vector<int> c;

int main() {
	assert(scanf("%d", &r) == 1);
	for (int tc = 0; tc < r; tc++) {
		assert(scanf("%d%d", &n, &k) == 2);
		u.resize(n - 1);
		v.resize(n - 1);
		adjlist.clear();
		adjlist.resize(n);
		for (int i = 0; i < n - 1; i++) {
			assert(scanf("%d%d", &u[i], &v[i]) == 2);
			adjlist[u[i]].push_back(v[i]);
			adjlist[v[i]].push_back(u[i]);
		}
		labels = label(n, k, u, v);
		if ((int)labels.size() != n) {
			printf("Number of labels not equal to %d\n", n);
			exit(0);
		}
		reverse_labels.clear();
		for (int i = 0; i < n; i++) {
			if (labels[i] < 0 || labels[i] > k) {
				printf("Label not in range 0 to %d\n", k);
				exit(0);
			}
			if (reverse_labels.find(labels[i]) != reverse_labels.end()) {
				printf("Labels not unique\n");
				exit(0);
			}
			reverse_labels[labels[i]] = i;
			if (labels[i] > max_label) {
				max_label = labels[i];
			}
		}
		assert(scanf("%d", &q) == 1);
		for (int i = 0; i < q; i++) {
			assert(scanf("%d%d%d", &s, &t, &w) == 3);
			c.clear();
			for (int v : adjlist[s]) {
				c.push_back(labels[v]);
			}
			std::sort(c.begin(), c.end());
			int answer = find_next_station(labels[s], labels[t], c);
			if (!std::binary_search(c.begin(), c.end(), answer)) {
				printf("Label %d returned by find_next_station not found in c\n", answer);
				exit(0);
			}
			answers.push_back(reverse_labels[answer]);
		}
	}
	printf("%d\n", max_label);
	for (int index : answers) {
		printf("%d\n", index);
	}
	exit(0);
}
*/

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:67:22: 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=1;i<c_out.size();i++)
      |                     ~^~~~~~~~~~~~~
stations.cpp:70:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         for(int i=0;i<c_in.size();i++)
      |                     ~^~~~~~~~~~~~
stations.cpp:80:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |         for(int i=0;i+1<c_in.size();i++)
      |                     ~~~^~~~~~~~~~~~
stations.cpp:90:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |         for(int i=0;i<c_in.size();i++)
      |                     ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 432 KB Invalid labels (values out of range). scenario=2, k=1000, vertex=1, label=1991
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 304 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1023
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 679 ms 628 KB Output is correct
2 Correct 533 ms 636 KB Output is correct
3 Correct 975 ms 404 KB Output is correct
4 Correct 667 ms 400 KB Output is correct
5 Correct 863 ms 516 KB Output is correct
6 Correct 517 ms 620 KB Output is correct
7 Correct 554 ms 492 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 8 ms 468 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 671 ms 544 KB Output is correct
12 Correct 589 ms 820 KB Output is correct
13 Correct 705 ms 748 KB Output is correct
14 Correct 614 ms 496 KB Output is correct
15 Correct 66 ms 528 KB Output is correct
16 Correct 70 ms 652 KB Output is correct
17 Correct 152 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 930 ms 544 KB Output is correct
2 Correct 928 ms 496 KB Output is correct
3 Correct 602 ms 508 KB Output is correct
4 Correct 6 ms 468 KB Output is correct
5 Correct 6 ms 420 KB Output is correct
6 Correct 3 ms 432 KB Output is correct
7 Correct 731 ms 492 KB Output is correct
8 Correct 1074 ms 496 KB Output is correct
9 Correct 795 ms 496 KB Output is correct
10 Correct 688 ms 508 KB Output is correct
11 Correct 7 ms 468 KB Output is correct
12 Correct 8 ms 512 KB Output is correct
13 Correct 8 ms 468 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 4 ms 468 KB Output is correct
16 Correct 640 ms 400 KB Output is correct
17 Correct 426 ms 496 KB Output is correct
18 Correct 495 ms 528 KB Output is correct
19 Correct 566 ms 400 KB Output is correct
20 Correct 616 ms 520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 566 ms 624 KB Partially correct
2 Partially correct 515 ms 652 KB Partially correct
3 Correct 1246 ms 400 KB Output is correct
4 Correct 1050 ms 400 KB Output is correct
5 Correct 703 ms 520 KB Output is correct
6 Partially correct 624 ms 632 KB Partially correct
7 Partially correct 565 ms 504 KB Partially correct
8 Correct 4 ms 464 KB Output is correct
9 Correct 4 ms 480 KB Output is correct
10 Correct 4 ms 464 KB Output is correct
11 Partially correct 554 ms 520 KB Partially correct
12 Partially correct 726 ms 496 KB Partially correct
13 Correct 1073 ms 572 KB Output is correct
14 Correct 746 ms 512 KB Output is correct
15 Correct 867 ms 512 KB Output is correct
16 Partially correct 481 ms 492 KB Partially correct
17 Correct 760 ms 400 KB Output is correct
18 Partially correct 630 ms 528 KB Partially correct
19 Partially correct 577 ms 756 KB Partially correct
20 Partially correct 616 ms 528 KB Partially correct
21 Correct 52 ms 528 KB Output is correct
22 Partially correct 98 ms 624 KB Partially correct
23 Partially correct 161 ms 656 KB Partially correct
24 Correct 6 ms 564 KB Output is correct
25 Correct 7 ms 404 KB Output is correct
26 Correct 8 ms 476 KB Output is correct
27 Correct 6 ms 604 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 630 ms 528 KB Output is correct
30 Correct 685 ms 520 KB Output is correct
31 Correct 533 ms 400 KB Output is correct
32 Correct 576 ms 512 KB Output is correct
33 Correct 447 ms 400 KB Output is correct
34 Partially correct 365 ms 620 KB Partially correct
35 Partially correct 557 ms 828 KB Partially correct
36 Partially correct 578 ms 740 KB Partially correct
37 Partially correct 530 ms 612 KB Partially correct
38 Partially correct 609 ms 768 KB Partially correct
39 Partially correct 681 ms 716 KB Partially correct
40 Partially correct 556 ms 768 KB Partially correct
41 Partially correct 666 ms 708 KB Partially correct
42 Partially correct 83 ms 656 KB Partially correct
43 Partially correct 106 ms 632 KB Partially correct
44 Partially correct 216 ms 520 KB Partially correct
45 Partially correct 160 ms 616 KB Partially correct
46 Partially correct 260 ms 552 KB Partially correct
47 Partially correct 368 ms 604 KB Partially correct
48 Partially correct 82 ms 756 KB Partially correct
49 Partially correct 97 ms 752 KB Partially correct