답안 #764987

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
764987 2023-06-24T07:16:20 Z drdilyor Šarenlist (COCI22_sarenlist) C++17
10 / 110
11 ms 468 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int inf = 1e9;
constexpr ll infl = 1e18;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, m, k;
    cin >> n >> m >> k;
    vector<vector<pair<int,int>>> adj(n);
    for( int i = 0; i < n-1; i++) {
        int a, b;
        cin >> a >> b;
        a--;b--;
        adj[a].emplace_back(b, i);
        adj[b].emplace_back(a, i);
    }
    vector<pair<int,int>> p(m);
    for (auto& [i, j] : p) cin >> i >> j, i--,j--;

    auto path = [&](auto& path, int i, int j, int p=-1)->optional<vector<int>>{
        if (i == j) return vector<int>{};
        for (auto [e, ei] : adj[i]) {
            if (e == p) continue;
            optional<vector<int>> res = path(path, e, j, i);
            if (res.has_value()) {
                res.value().push_back(ei);
                return res;
            }
        }
        return nullopt;
    };

    assert(n <= 15 && k == 2);
    int res = 0;
    for (int mask = 0; mask < (1<<(n-1)); mask++) {
        bool ok = 1;
        for (auto[i, j] : p) {
            vector edges = path(path, i, j).value();
            int black = 0, white = 0;
            for (int e : edges) {
                if (mask & (1<<e)) black++;
                else white++;
            }
            if (!black || !white) ok = 0;
            if (!ok) break;
        }
        res += ok;
    }
    cout << res << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 3 ms 316 KB Output is correct
6 Correct 11 ms 316 KB Output is correct
7 Correct 8 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -