답안 #907423

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
907423 2024-01-15T14:03:39 Z Pikachu 기지국 (IOI20_stations) C++17
100 / 100
583 ms 1440 KB
#include <bits/stdc++.h>
#include "stations.h"
 
using namespace std;
 
vector<int> label(int n, int k, vector<int> u, vector<int> v) 
{
	vector<int> labels(n);
    vector<vector<int> > adj(n);
    
    for (int i = 0; i < n - 1; i++) {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }
	
    vector<int> ti(n), to(n);
    int T = 0;
    auto DFS = [&] (auto DFS, int u, int par, int h) -> void
    {
        ti[u] = ++T;
        for (int i = 0; i < (int)adj[u].size(); i++) {
            if (adj[u][i] == par) {
                adj[u].erase(adj[u].begin() + i); 
                break;
            }
        }
        if (adj[u].size()) {
            for (int i = 0; i < (int)adj[u].size() - 1; i++) {
                DFS(DFS, adj[u][i], u, h + 1);
            }
            DFS(DFS, adj[u].back(), u, h + 1);
        }
        to[u] = ++T;
        if (h & 1) labels[u] = ti[u];
        else labels[u] = to[u];
    };
    DFS(DFS, 0, -1, 0);
  	vector<int> mpg;
 	for (int i = 0; i < n; i++) {
        mpg.push_back(labels[i]);
    }
    sort(mpg.begin(), mpg.end());
    for (int i = 0; i < n; i++) {
        labels[i] = lower_bound(mpg.begin(), mpg.end(), labels[i]) - mpg.begin() + 1;
    }
	return labels;
}
 
int find_next_station(int s, int t, vector<int> c) 
{
    if (s > c.back()) {
        for (int i = 1; i < (int)c.size() - 1; i++) {
            if (c[i] <= t && t < c[i + 1]) return c[i];
        }
        if (c.back() <= t && t < s) return c.back();
        return c.front();
    }
    else {
        for (int i = 1; i < (int)c.size() - 1; i++) {
            if (c[i - 1] < t && t <= c[i]) return c[i];
        }
        if (s <= t && t <= c.front()) return c.front();
        return c.back();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 364 ms 976 KB Output is correct
2 Correct 294 ms 984 KB Output is correct
3 Correct 528 ms 684 KB Output is correct
4 Correct 391 ms 744 KB Output is correct
5 Correct 365 ms 936 KB Output is correct
6 Correct 262 ms 960 KB Output is correct
7 Correct 261 ms 772 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 1 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 273 ms 864 KB Output is correct
2 Correct 309 ms 796 KB Output is correct
3 Correct 504 ms 684 KB Output is correct
4 Correct 409 ms 684 KB Output is correct
5 Correct 394 ms 772 KB Output is correct
6 Correct 257 ms 688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 326 ms 988 KB Output is correct
2 Correct 275 ms 980 KB Output is correct
3 Correct 534 ms 684 KB Output is correct
4 Correct 377 ms 684 KB Output is correct
5 Correct 395 ms 684 KB Output is correct
6 Correct 261 ms 956 KB Output is correct
7 Correct 266 ms 940 KB Output is correct
8 Correct 2 ms 764 KB Output is correct
9 Correct 3 ms 708 KB Output is correct
10 Correct 1 ms 764 KB Output is correct
11 Correct 349 ms 936 KB Output is correct
12 Correct 287 ms 968 KB Output is correct
13 Correct 315 ms 1220 KB Output is correct
14 Correct 278 ms 684 KB Output is correct
15 Correct 35 ms 768 KB Output is correct
16 Correct 45 ms 832 KB Output is correct
17 Correct 71 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 528 ms 684 KB Output is correct
2 Correct 397 ms 936 KB Output is correct
3 Correct 365 ms 856 KB Output is correct
4 Correct 2 ms 764 KB Output is correct
5 Correct 3 ms 764 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 320 ms 684 KB Output is correct
8 Correct 583 ms 684 KB Output is correct
9 Correct 373 ms 684 KB Output is correct
10 Correct 333 ms 884 KB Output is correct
11 Correct 3 ms 764 KB Output is correct
12 Correct 4 ms 768 KB Output is correct
13 Correct 4 ms 764 KB Output is correct
14 Correct 3 ms 764 KB Output is correct
15 Correct 2 ms 764 KB Output is correct
16 Correct 265 ms 684 KB Output is correct
17 Correct 294 ms 688 KB Output is correct
18 Correct 303 ms 684 KB Output is correct
19 Correct 310 ms 684 KB Output is correct
20 Correct 287 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 343 ms 1208 KB Output is correct
2 Correct 252 ms 972 KB Output is correct
3 Correct 581 ms 688 KB Output is correct
4 Correct 408 ms 684 KB Output is correct
5 Correct 394 ms 684 KB Output is correct
6 Correct 339 ms 980 KB Output is correct
7 Correct 254 ms 684 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 294 ms 872 KB Output is correct
12 Correct 282 ms 956 KB Output is correct
13 Correct 560 ms 684 KB Output is correct
14 Correct 376 ms 684 KB Output is correct
15 Correct 381 ms 684 KB Output is correct
16 Correct 274 ms 684 KB Output is correct
17 Correct 331 ms 684 KB Output is correct
18 Correct 264 ms 1280 KB Output is correct
19 Correct 271 ms 1324 KB Output is correct
20 Correct 269 ms 684 KB Output is correct
21 Correct 28 ms 684 KB Output is correct
22 Correct 44 ms 1144 KB Output is correct
23 Correct 59 ms 972 KB Output is correct
24 Correct 4 ms 768 KB Output is correct
25 Correct 4 ms 760 KB Output is correct
26 Correct 3 ms 764 KB Output is correct
27 Correct 3 ms 764 KB Output is correct
28 Correct 1 ms 768 KB Output is correct
29 Correct 303 ms 684 KB Output is correct
30 Correct 255 ms 684 KB Output is correct
31 Correct 303 ms 684 KB Output is correct
32 Correct 294 ms 688 KB Output is correct
33 Correct 285 ms 940 KB Output is correct
34 Correct 179 ms 928 KB Output is correct
35 Correct 245 ms 1232 KB Output is correct
36 Correct 259 ms 1212 KB Output is correct
37 Correct 263 ms 964 KB Output is correct
38 Correct 266 ms 1140 KB Output is correct
39 Correct 280 ms 1164 KB Output is correct
40 Correct 257 ms 1168 KB Output is correct
41 Correct 265 ms 1152 KB Output is correct
42 Correct 35 ms 876 KB Output is correct
43 Correct 65 ms 1440 KB Output is correct
44 Correct 77 ms 872 KB Output is correct
45 Correct 102 ms 924 KB Output is correct
46 Correct 191 ms 880 KB Output is correct
47 Correct 184 ms 928 KB Output is correct
48 Correct 40 ms 924 KB Output is correct
49 Correct 32 ms 1228 KB Output is correct