답안 #872169

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
872169 2023-11-12T12:12:35 Z overwatch9 Regions (IOI09_regions) C++17
0 / 100
1 ms 600 KB
#include <iostream>
#include <unordered_map>
#include <set>
#include <vector>
using namespace std;
const int maxn = 10;
int visit[maxn], finish[maxn], region[maxn];
vector <int> adj[maxn];
vector <int> regions[maxn];
int t = 0;
void dfs(int s, int p) {
    visit[s] = t++;
    regions[region[s]].push_back(s);
    for (auto i : adj[s])
        dfs(i, s);
    finish[s] = t;
}
bool is_ancestor(int a, int b) {
    return visit[a] <= visit[b] && finish[a] >= finish[b];
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, r, q;
    cin >> n >> r >> q;
    cin >> region[1];
    for (int i = 2; i <= n; i++) {
        int x;
        cin >> x;
        adj[x].push_back(i);
        cin >> region[i];
    }
    dfs(1, 1);
    while (q--) {
        int r1, r2;
        cin >> r1 >> r2;
        int ans = 0;
        int p1 = 0, p2 = 0;
        int moved = 0;
        while (p1 < regions[r1].size() && p2 < regions[r2].size()) {
            if (is_ancestor(regions[r1][p1], regions[r2][p2])) {
                while (p2 < regions[r2].size() && is_ancestor(regions[r1][p1], regions[r2][p2])) {
                    p2++;
                    moved++;
                }
                ans += moved;
            } else if (is_ancestor(regions[r2][p2], regions[r1][p1])) {
                while (p2 < regions[r2].size() && is_ancestor(regions[r2][p2], regions[r1][p1])) {
                    p2++;
                    moved = 0;
                }
            } else {
                p1++;
                moved = 0;
            }
        }
        cout << ans << endl;
    }
}

Compilation message

regions.cpp: In function 'int main()':
regions.cpp:41:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         while (p1 < regions[r1].size() && p2 < regions[r2].size()) {
      |                ~~~^~~~~~~~~~~~~~~~~~~~
regions.cpp:41:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         while (p1 < regions[r1].size() && p2 < regions[r2].size()) {
      |                                           ~~~^~~~~~~~~~~~~~~~~~~~
regions.cpp:43:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |                 while (p2 < regions[r2].size() && is_ancestor(regions[r1][p1], regions[r2][p2])) {
      |                        ~~~^~~~~~~~~~~~~~~~~~~~
regions.cpp:49:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |                 while (p2 < regions[r2].size() && is_ancestor(regions[r2][p2], regions[r1][p1])) {
      |                        ~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Runtime error 0 ms 344 KB Execution killed with signal 11
3 Runtime error 1 ms 344 KB Execution killed with signal 11
4 Runtime error 0 ms 344 KB Execution killed with signal 11
5 Runtime error 0 ms 344 KB Execution killed with signal 11
6 Runtime error 1 ms 344 KB Execution killed with signal 11
7 Runtime error 0 ms 344 KB Execution killed with signal 11
8 Runtime error 1 ms 600 KB Execution killed with signal 11
9 Runtime error 0 ms 344 KB Execution killed with signal 11
10 Runtime error 0 ms 344 KB Execution killed with signal 11
11 Runtime error 0 ms 344 KB Execution killed with signal 11
12 Runtime error 0 ms 600 KB Execution killed with signal 11
13 Runtime error 1 ms 344 KB Execution killed with signal 11
14 Runtime error 1 ms 600 KB Execution killed with signal 11
15 Runtime error 0 ms 344 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Runtime error 1 ms 344 KB Execution killed with signal 11
3 Runtime error 0 ms 344 KB Execution killed with signal 11
4 Runtime error 1 ms 600 KB Execution killed with signal 11
5 Runtime error 1 ms 344 KB Execution killed with signal 11
6 Runtime error 1 ms 600 KB Execution killed with signal 11
7 Runtime error 1 ms 344 KB Execution killed with signal 11
8 Runtime error 1 ms 344 KB Execution killed with signal 11
9 Runtime error 1 ms 344 KB Execution killed with signal 11
10 Runtime error 0 ms 344 KB Execution killed with signal 11
11 Runtime error 1 ms 344 KB Execution killed with signal 11
12 Runtime error 0 ms 600 KB Execution killed with signal 11
13 Runtime error 1 ms 344 KB Execution killed with signal 11
14 Runtime error 1 ms 600 KB Execution killed with signal 11
15 Runtime error 1 ms 344 KB Execution killed with signal 11
16 Runtime error 0 ms 344 KB Execution killed with signal 11
17 Runtime error 0 ms 600 KB Execution killed with signal 11