답안 #402553

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
402553 2021-05-11T23:32:04 Z Nnandi 기지국 (IOI20_stations) C++14
100 / 100
1124 ms 712 KB
#include "stations.h"
#include <vector>
#include <algorithm>

void dfs(std::vector<std::vector<int> > &graph, std::vector<int> &labels, int p, bool nodeType, int &clock) {
    labels[p] = -1;

    if(nodeType == true) {
        labels[p] = clock;
        clock++;
    }

    for(int q:graph[p]) {
        if(labels[q] == -2) {
            dfs(graph,labels,q,!nodeType,clock);
        }
    }

    if(nodeType == false) {
        labels[p] = clock;
        clock++;
    }

    return;
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {

	//graph transformation

	std::vector<std::vector< int > > graph(n);
	for(int i=0;i<n-1;i++) {
        graph[u[i]].push_back(v[i]);
        graph[v[i]].push_back(u[i]);
	}

	std::vector<int> labels(n,-2);

	//labeling process

	bool initNode = true;
	int clock = 0;
	dfs(graph,labels,0,initNode,clock);

	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	//finding out the node type
	std::sort(c.begin(),c.end());

	int degree = c.size();
	int fatherNode;

	if(s < c[0]) {
        //s is labeled by arrival time
        fatherNode = c[degree - 1];
        if(t < s || t > fatherNode) {
            //should be sent to father node
            return fatherNode;
        }
        int dest = -1;
        for(int q:c) {
            if(t <= q && dest == -1) {
                dest = q;
            }
        }
        return dest;
	}
	else {
        //s is labeled by departure time
        std::reverse(c.begin(),c.end());
        fatherNode = c[degree - 1];
        if(t > s || t < fatherNode) {
            //should be sent to father node
            return fatherNode;
        }
        int dest = -1;
        for(int q:c) {
            if(t >= q && dest == -1) {
                dest = q;
            }
        }
        return dest;

	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 681 ms 528 KB Output is correct
2 Correct 567 ms 604 KB Output is correct
3 Correct 1007 ms 480 KB Output is correct
4 Correct 763 ms 476 KB Output is correct
5 Correct 638 ms 400 KB Output is correct
6 Correct 532 ms 532 KB Output is correct
7 Correct 622 ms 464 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 477 ms 468 KB Output is correct
2 Correct 613 ms 532 KB Output is correct
3 Correct 1037 ms 656 KB Output is correct
4 Correct 773 ms 464 KB Output is correct
5 Correct 628 ms 400 KB Output is correct
6 Correct 535 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 563 ms 712 KB Output is correct
2 Correct 426 ms 600 KB Output is correct
3 Correct 1124 ms 400 KB Output is correct
4 Correct 833 ms 524 KB Output is correct
5 Correct 657 ms 476 KB Output is correct
6 Correct 575 ms 528 KB Output is correct
7 Correct 530 ms 528 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 5 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 656 ms 400 KB Output is correct
12 Correct 573 ms 668 KB Output is correct
13 Correct 570 ms 596 KB Output is correct
14 Correct 451 ms 656 KB Output is correct
15 Correct 65 ms 400 KB Output is correct
16 Correct 83 ms 528 KB Output is correct
17 Correct 109 ms 528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 917 ms 472 KB Output is correct
2 Correct 751 ms 528 KB Output is correct
3 Correct 736 ms 400 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 6 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 672 ms 400 KB Output is correct
8 Correct 1109 ms 476 KB Output is correct
9 Correct 778 ms 400 KB Output is correct
10 Correct 663 ms 400 KB Output is correct
11 Correct 7 ms 476 KB Output is correct
12 Correct 6 ms 468 KB Output is correct
13 Correct 6 ms 468 KB Output is correct
14 Correct 3 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 565 ms 520 KB Output is correct
17 Correct 560 ms 404 KB Output is correct
18 Correct 598 ms 480 KB Output is correct
19 Correct 708 ms 472 KB Output is correct
20 Correct 493 ms 400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 656 ms 608 KB Output is correct
2 Correct 462 ms 528 KB Output is correct
3 Correct 957 ms 472 KB Output is correct
4 Correct 815 ms 400 KB Output is correct
5 Correct 657 ms 576 KB Output is correct
6 Correct 456 ms 592 KB Output is correct
7 Correct 638 ms 532 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 6 ms 476 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 444 ms 556 KB Output is correct
12 Correct 711 ms 544 KB Output is correct
13 Correct 971 ms 528 KB Output is correct
14 Correct 791 ms 400 KB Output is correct
15 Correct 804 ms 528 KB Output is correct
16 Correct 525 ms 456 KB Output is correct
17 Correct 608 ms 404 KB Output is correct
18 Correct 486 ms 604 KB Output is correct
19 Correct 585 ms 592 KB Output is correct
20 Correct 479 ms 528 KB Output is correct
21 Correct 54 ms 464 KB Output is correct
22 Correct 76 ms 528 KB Output is correct
23 Correct 112 ms 528 KB Output is correct
24 Correct 6 ms 472 KB Output is correct
25 Correct 5 ms 476 KB Output is correct
26 Correct 5 ms 596 KB Output is correct
27 Correct 5 ms 468 KB Output is correct
28 Correct 2 ms 476 KB Output is correct
29 Correct 653 ms 476 KB Output is correct
30 Correct 588 ms 400 KB Output is correct
31 Correct 681 ms 476 KB Output is correct
32 Correct 596 ms 404 KB Output is correct
33 Correct 552 ms 468 KB Output is correct
34 Correct 416 ms 468 KB Output is correct
35 Correct 538 ms 544 KB Output is correct
36 Correct 460 ms 592 KB Output is correct
37 Correct 568 ms 600 KB Output is correct
38 Correct 478 ms 656 KB Output is correct
39 Correct 558 ms 656 KB Output is correct
40 Correct 485 ms 592 KB Output is correct
41 Correct 575 ms 592 KB Output is correct
42 Correct 71 ms 556 KB Output is correct
43 Correct 125 ms 528 KB Output is correct
44 Correct 164 ms 528 KB Output is correct
45 Correct 228 ms 552 KB Output is correct
46 Correct 359 ms 528 KB Output is correct
47 Correct 406 ms 528 KB Output is correct
48 Correct 82 ms 556 KB Output is correct
49 Correct 79 ms 572 KB Output is correct