# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1044082 | 2024-08-05T07:11:25 Z | 우민규(#11006) | Parking (CEOI22_parking) | C++17 | 76 ms | 16284 KB |
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> fst, snd; // bottom -> up then true, up -> bottom then false vector<vector<int>> adj; vector<int> type; // determine type vector<bool> visited, is_selfloop; enum Component { TrivialPath, SplitPath, PerfectCycle, SplitCycle, ComplexCycle, SelfLoop, EmptySelfLoop, }; // {amt of top, saw path} pair<int, bool> dfs(int node) { visited[node] = true; int top_amt = type[node] == 3; bool is_path = false; for (auto v : adj[node]) { if (visited[v]) continue; if (v == 0) { is_path = true; } else { auto [tt, ip] = dfs(v); top_amt += tt; is_path |= ip; } } return {top_amt, is_path}; } Component component_type(int node) { if (is_selfloop[node]) return SelfLoop; auto [top_amt, is_path] = dfs(node); if (is_path) { if (top_amt) return SplitPath; return TrivialPath; } if (top_amt > 1) return ComplexCycle; if (top_amt) return SplitCycle; return PerfectCycle; } void solve() { cin >> n >> m; adj.assign(n + 1, {}), type.assign(n + 1, 0), visited.assign(n + 1, false), is_selfloop.assign(n + 1, false); int num_type[7]{}; for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; if (a) type[a] = 2 * type[a]; if (b) type[b] = 2 * type[b] + 1; fst.push_back(a), snd.push_back(b); adj[a].push_back(b), adj[b].push_back(a); if (a == 0 && b == 0) { num_type[EmptySelfLoop] += 1; } if (a == b) { is_selfloop[a] = true; } } // determine all endpoints for (int i = 1; i <= n; ++i) { if (!visited[i]) { num_type[component_type(i)] += 1; } } int req_moves = num_type[PerfectCycle]; for (int i = 1; i <= n; ++i) { if (is_selfloop[i]) continue; req_moves += 1; if (type[i] == 3) req_moves += 1; } // Check if it's possible num_type[EmptySelfLoop] += num_type[TrivialPath]; num_type[TrivialPath] = 0; if (num_type[EmptySelfLoop] == 0 && (num_type[SplitPath] > 0 || num_type[PerfectCycle] > 0 || num_type[SplitCycle] > 0 || num_type[ComplexCycle] > 0)) { cout << "-1\n"; return; } num_type[EmptySelfLoop] += num_type[SplitPath]; if (num_type[ComplexCycle] > 0) { if (num_type[EmptySelfLoop] < 2) { cout << "-1\n"; return; } } cout << req_moves << "\n"; } int main() { cin.tie(0)->sync_with_stdio(0); int t = 1; solve(); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Partially correct | 0 ms | 344 KB | Output is partially correct |
2 | Partially correct | 0 ms | 348 KB | Output is partially correct |
3 | Partially correct | 0 ms | 348 KB | Output is partially correct |
4 | Partially correct | 0 ms | 348 KB | Output is partially correct |
5 | Partially correct | 1 ms | 348 KB | Output is partially correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Partially correct | 1 ms | 348 KB | Output is partially correct |
8 | Correct | 1 ms | 600 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Partially correct | 0 ms | 348 KB | Output is partially correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Partially correct | 29 ms | 7344 KB | Output is partially correct |
2 | Partially correct | 27 ms | 8468 KB | Output is partially correct |
3 | Partially correct | 26 ms | 7228 KB | Output is partially correct |
4 | Partially correct | 21 ms | 6928 KB | Output is partially correct |
5 | Partially correct | 29 ms | 8376 KB | Output is partially correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Partially correct | 1 ms | 348 KB | Output is partially correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Partially correct | 1 ms | 344 KB | Output is partially correct |
5 | Correct | 1 ms | 344 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Partially correct | 1 ms | 344 KB | Output is partially correct |
8 | Correct | 0 ms | 352 KB | Output is correct |
9 | Partially correct | 1 ms | 344 KB | Output is partially correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Partially correct | 1 ms | 348 KB | Output is partially correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Partially correct | 1 ms | 344 KB | Output is partially correct |
5 | Correct | 1 ms | 344 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Partially correct | 1 ms | 344 KB | Output is partially correct |
8 | Correct | 0 ms | 352 KB | Output is correct |
9 | Partially correct | 1 ms | 344 KB | Output is partially correct |
10 | Partially correct | 62 ms | 15936 KB | Output is partially correct |
11 | Correct | 43 ms | 15756 KB | Output is correct |
12 | Correct | 67 ms | 15784 KB | Output is correct |
13 | Partially correct | 67 ms | 15756 KB | Output is partially correct |
14 | Correct | 69 ms | 16284 KB | Output is correct |
15 | Correct | 57 ms | 15676 KB | Output is correct |
16 | Partially correct | 76 ms | 16188 KB | Output is partially correct |
17 | Correct | 60 ms | 15620 KB | Output is correct |
18 | Partially correct | 54 ms | 16236 KB | Output is partially correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Partially correct | 0 ms | 348 KB | Output is partially correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Partially correct | 1 ms | 348 KB | Output is partially correct |
4 | Partially correct | 0 ms | 348 KB | Output is partially correct |
5 | Correct | 1 ms | 604 KB | Output is correct |
6 | Partially correct | 0 ms | 344 KB | Output is partially correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Partially correct | 1 ms | 348 KB | Output is partially correct |
9 | Partially correct | 1 ms | 344 KB | Output is partially correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Partially correct | 0 ms | 348 KB | Output is partially correct |
12 | Partially correct | 0 ms | 344 KB | Output is partially correct |
13 | Correct | 1 ms | 344 KB | Output is correct |
14 | Correct | 1 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Partially correct | 0 ms | 344 KB | Output is partially correct |
17 | Correct | 0 ms | 344 KB | Output is correct |
18 | Partially correct | 1 ms | 348 KB | Output is partially correct |
19 | Partially correct | 1 ms | 348 KB | Output is partially correct |
20 | Partially correct | 1 ms | 348 KB | Output is partially correct |
21 | Correct | 0 ms | 344 KB | Output is correct |
22 | Partially correct | 1 ms | 348 KB | Output is partially correct |
23 | Correct | 0 ms | 344 KB | Output is correct |
24 | Partially correct | 0 ms | 348 KB | Output is partially correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Partially correct | 0 ms | 344 KB | Output is partially correct |
2 | Partially correct | 0 ms | 348 KB | Output is partially correct |
3 | Partially correct | 0 ms | 348 KB | Output is partially correct |
4 | Partially correct | 0 ms | 348 KB | Output is partially correct |
5 | Partially correct | 1 ms | 348 KB | Output is partially correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Partially correct | 1 ms | 348 KB | Output is partially correct |
8 | Correct | 1 ms | 600 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Partially correct | 0 ms | 348 KB | Output is partially correct |
11 | Partially correct | 29 ms | 7344 KB | Output is partially correct |
12 | Partially correct | 27 ms | 8468 KB | Output is partially correct |
13 | Partially correct | 26 ms | 7228 KB | Output is partially correct |
14 | Partially correct | 21 ms | 6928 KB | Output is partially correct |
15 | Partially correct | 29 ms | 8376 KB | Output is partially correct |
16 | Partially correct | 1 ms | 348 KB | Output is partially correct |
17 | Correct | 1 ms | 344 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Partially correct | 1 ms | 344 KB | Output is partially correct |
20 | Correct | 1 ms | 344 KB | Output is correct |
21 | Correct | 1 ms | 348 KB | Output is correct |
22 | Partially correct | 1 ms | 344 KB | Output is partially correct |
23 | Correct | 0 ms | 352 KB | Output is correct |
24 | Partially correct | 1 ms | 344 KB | Output is partially correct |
25 | Partially correct | 62 ms | 15936 KB | Output is partially correct |
26 | Correct | 43 ms | 15756 KB | Output is correct |
27 | Correct | 67 ms | 15784 KB | Output is correct |
28 | Partially correct | 67 ms | 15756 KB | Output is partially correct |
29 | Correct | 69 ms | 16284 KB | Output is correct |
30 | Correct | 57 ms | 15676 KB | Output is correct |
31 | Partially correct | 76 ms | 16188 KB | Output is partially correct |
32 | Correct | 60 ms | 15620 KB | Output is correct |
33 | Partially correct | 54 ms | 16236 KB | Output is partially correct |
34 | Partially correct | 0 ms | 348 KB | Output is partially correct |
35 | Correct | 1 ms | 348 KB | Output is correct |
36 | Partially correct | 1 ms | 348 KB | Output is partially correct |
37 | Partially correct | 0 ms | 348 KB | Output is partially correct |
38 | Correct | 1 ms | 604 KB | Output is correct |
39 | Partially correct | 0 ms | 344 KB | Output is partially correct |
40 | Correct | 1 ms | 348 KB | Output is correct |
41 | Partially correct | 1 ms | 348 KB | Output is partially correct |
42 | Partially correct | 1 ms | 344 KB | Output is partially correct |
43 | Correct | 1 ms | 348 KB | Output is correct |
44 | Partially correct | 0 ms | 348 KB | Output is partially correct |
45 | Partially correct | 0 ms | 344 KB | Output is partially correct |
46 | Correct | 1 ms | 344 KB | Output is correct |
47 | Correct | 1 ms | 348 KB | Output is correct |
48 | Correct | 1 ms | 348 KB | Output is correct |
49 | Partially correct | 0 ms | 344 KB | Output is partially correct |
50 | Correct | 0 ms | 344 KB | Output is correct |
51 | Partially correct | 1 ms | 348 KB | Output is partially correct |
52 | Partially correct | 1 ms | 348 KB | Output is partially correct |
53 | Partially correct | 1 ms | 348 KB | Output is partially correct |
54 | Correct | 0 ms | 344 KB | Output is correct |
55 | Partially correct | 1 ms | 348 KB | Output is partially correct |
56 | Correct | 0 ms | 344 KB | Output is correct |
57 | Partially correct | 0 ms | 348 KB | Output is partially correct |
58 | Partially correct | 49 ms | 14572 KB | Output is partially correct |
59 | Partially correct | 49 ms | 15928 KB | Output is partially correct |
60 | Partially correct | 54 ms | 13368 KB | Output is partially correct |
61 | Partially correct | 60 ms | 14908 KB | Output is partially correct |
62 | Correct | 42 ms | 16192 KB | Output is correct |
63 | Partially correct | 61 ms | 15676 KB | Output is partially correct |
64 | Correct | 63 ms | 16184 KB | Output is correct |
65 | Partially correct | 59 ms | 15416 KB | Output is partially correct |
66 | Partially correct | 56 ms | 16080 KB | Output is partially correct |
67 | Correct | 47 ms | 15444 KB | Output is correct |
68 | Partially correct | 52 ms | 15940 KB | Output is partially correct |
69 | Partially correct | 51 ms | 15672 KB | Output is partially correct |
70 | Correct | 48 ms | 15656 KB | Output is correct |
71 | Correct | 52 ms | 15928 KB | Output is correct |
72 | Correct | 51 ms | 15736 KB | Output is correct |
73 | Partially correct | 53 ms | 16064 KB | Output is partially correct |
74 | Correct | 46 ms | 15672 KB | Output is correct |
75 | Partially correct | 47 ms | 15672 KB | Output is partially correct |
76 | Partially correct | 52 ms | 16064 KB | Output is partially correct |
77 | Partially correct | 49 ms | 15424 KB | Output is partially correct |
78 | Correct | 48 ms | 15932 KB | Output is correct |
79 | Partially correct | 43 ms | 15420 KB | Output is partially correct |
80 | Correct | 47 ms | 15576 KB | Output is correct |
81 | Partially correct | 63 ms | 15972 KB | Output is partially correct |