답안 #781009

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781009 2023-07-12T15:35:44 Z Josia 기지국 (IOI20_stations) C++17
100 / 100
749 ms 824 KB
#include "stations.h"
#include <bits/stdc++.h>

using namespace std;




vector<int> pre;
vector<int> post;
vector<vector<int>> graph;
vector<int> depth;

int tim;
void dfs(int v, int d) {
	if (pre[v] != -1) return;
	pre[v] = tim++;
	depth[v] = d;
	for (int i: graph[v]) {
		dfs(i, d+1);
	}
	post[v] = tim++;
}


vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	tim = 0;
	pre.assign(n, -1);
	post.assign(n, -1);
	depth.assign(n, -1);
	graph.clear(); graph.resize(n);

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

	dfs(0, 0);

	// for (int i: pre) cerr << i << " ";
	// cerr << "\n";


	vector<int> labels(n);

    int mod = labels[0]%2;

	for (int i=0; i<n; i++) {
		if (depth[i]%2) labels[i] = pre[i];
		else labels[i] = post[i];
	}


    vector<pair<int, int>> comp(n);
	for (int i=0; i<n; i++) {
		comp[i] = {labels[i], i};
	}
    sort(comp.begin(), comp.end());

    for (int i=0; i<n; i++) {
        comp[i].first = i;
        swap(comp[i].first, comp[i].second);
    }
    sort(comp.begin(), comp.end());

    for (int i = 0; i<n; i++) {
        labels[i] = comp[i].second;
    }

	return labels;
}

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

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

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

	bool bound = s > c[0];      // 0 lower; 1 higher

    if (bound == 0) {
        if (t < s) return c.back();
        if (t > *prev(c.end())) return c.back();

        for (int i = 1; i<c.size(); i++) {
            if (t > c[i-1] && t <= c[i]) return c[i];
        }

        return c[0];
    }
    else {
        if (t > s) return c[0];
        if (t < c[1]) return c[0];

        for (int i = 0; i<c.size()-1; i++) {
            if (t < c[i+1] && t >= c[i]) return c[i];
        }

        return c.back();
    }

}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:46:9: warning: unused variable 'mod' [-Wunused-variable]
   46 |     int mod = labels[0]%2;
      |         ^~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:85:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |         for (int i = 1; i<c.size(); i++) {
      |                         ~^~~~~~~~~
stations.cpp:95:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |         for (int i = 0; i<c.size()-1; i++) {
      |                         ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 498 ms 544 KB Output is correct
2 Correct 284 ms 632 KB Output is correct
3 Correct 716 ms 504 KB Output is correct
4 Correct 615 ms 420 KB Output is correct
5 Correct 486 ms 420 KB Output is correct
6 Correct 332 ms 632 KB Output is correct
7 Correct 286 ms 544 KB Output is correct
8 Correct 1 ms 500 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 319 ms 628 KB Output is correct
2 Correct 404 ms 548 KB Output is correct
3 Correct 685 ms 504 KB Output is correct
4 Correct 554 ms 416 KB Output is correct
5 Correct 389 ms 500 KB Output is correct
6 Correct 449 ms 544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 520 ms 672 KB Output is correct
2 Correct 312 ms 632 KB Output is correct
3 Correct 660 ms 508 KB Output is correct
4 Correct 486 ms 416 KB Output is correct
5 Correct 490 ms 548 KB Output is correct
6 Correct 354 ms 544 KB Output is correct
7 Correct 341 ms 500 KB Output is correct
8 Correct 2 ms 488 KB Output is correct
9 Correct 4 ms 492 KB Output is correct
10 Correct 0 ms 500 KB Output is correct
11 Correct 412 ms 420 KB Output is correct
12 Correct 424 ms 544 KB Output is correct
13 Correct 304 ms 596 KB Output is correct
14 Correct 304 ms 544 KB Output is correct
15 Correct 45 ms 492 KB Output is correct
16 Correct 61 ms 600 KB Output is correct
17 Correct 100 ms 572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 643 ms 500 KB Output is correct
2 Correct 632 ms 500 KB Output is correct
3 Correct 554 ms 416 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 1 ms 488 KB Output is correct
6 Correct 0 ms 492 KB Output is correct
7 Correct 440 ms 504 KB Output is correct
8 Correct 693 ms 420 KB Output is correct
9 Correct 570 ms 500 KB Output is correct
10 Correct 422 ms 420 KB Output is correct
11 Correct 4 ms 500 KB Output is correct
12 Correct 3 ms 500 KB Output is correct
13 Correct 3 ms 416 KB Output is correct
14 Correct 4 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 322 ms 416 KB Output is correct
17 Correct 376 ms 420 KB Output is correct
18 Correct 368 ms 528 KB Output is correct
19 Correct 322 ms 504 KB Output is correct
20 Correct 473 ms 516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 480 ms 672 KB Output is correct
2 Correct 403 ms 640 KB Output is correct
3 Correct 702 ms 504 KB Output is correct
4 Correct 543 ms 508 KB Output is correct
5 Correct 527 ms 512 KB Output is correct
6 Correct 337 ms 548 KB Output is correct
7 Correct 415 ms 504 KB Output is correct
8 Correct 2 ms 500 KB Output is correct
9 Correct 2 ms 500 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 281 ms 676 KB Output is correct
12 Correct 370 ms 548 KB Output is correct
13 Correct 749 ms 464 KB Output is correct
14 Correct 540 ms 500 KB Output is correct
15 Correct 571 ms 420 KB Output is correct
16 Correct 381 ms 504 KB Output is correct
17 Correct 580 ms 420 KB Output is correct
18 Correct 406 ms 712 KB Output is correct
19 Correct 468 ms 748 KB Output is correct
20 Correct 373 ms 504 KB Output is correct
21 Correct 46 ms 444 KB Output is correct
22 Correct 61 ms 600 KB Output is correct
23 Correct 95 ms 544 KB Output is correct
24 Correct 5 ms 500 KB Output is correct
25 Correct 4 ms 492 KB Output is correct
26 Correct 3 ms 500 KB Output is correct
27 Correct 3 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 487 ms 420 KB Output is correct
30 Correct 390 ms 420 KB Output is correct
31 Correct 398 ms 420 KB Output is correct
32 Correct 348 ms 504 KB Output is correct
33 Correct 386 ms 416 KB Output is correct
34 Correct 264 ms 544 KB Output is correct
35 Correct 303 ms 640 KB Output is correct
36 Correct 403 ms 660 KB Output is correct
37 Correct 321 ms 644 KB Output is correct
38 Correct 366 ms 708 KB Output is correct
39 Correct 354 ms 824 KB Output is correct
40 Correct 400 ms 716 KB Output is correct
41 Correct 334 ms 584 KB Output is correct
42 Correct 45 ms 584 KB Output is correct
43 Correct 88 ms 696 KB Output is correct
44 Correct 101 ms 572 KB Output is correct
45 Correct 121 ms 620 KB Output is correct
46 Correct 289 ms 544 KB Output is correct
47 Correct 285 ms 544 KB Output is correct
48 Correct 55 ms 688 KB Output is correct
49 Correct 45 ms 804 KB Output is correct