답안 #677772

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
677772 2023-01-04T10:56:46 Z someone 늑대인간 (IOI18_werewolf) C++14
100 / 100
662 ms 81116 KB
#include <bits/stdc++.h>
using namespace std;
 
const int N = 2e5 + 42;
 
set<int> vals[N];
vector<int> adj[N], fils[N], req[N];
int n, m, q, id = 0, sz[N], par[N], pds[N], deb[N], fin[N];
 
int F(int i) {
    if(par[i] == i)
        return i;
    return par[i] = F(par[i]);
}

void U(int a, int b) {
    a = F(a), b = F(b);
    if(a == b) return;
    if((int)vals[a].size() < (int)vals[b].size())
        swap(a, b);
    par[b] = a;
    for(int i : vals[b])
        vals[a].insert(i);
    vals[b].clear();
}

int nbit = 0;

void dfs(int i) {
    deb[i] = id++;
    for(int j : fils[i])
        dfs(j);
    fin[i] = id;
}

vector<int> check_validity(int NB, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) {
    n = NB, m = (int)X.size(), q = (int)S.size();
    vector<int> ans(q);
    for(int i = 0; i < n; i++)
        par[i] = i;
    for(int i = 0; i < m; i++) {
        adj[X[i]].push_back(Y[i]);
        adj[Y[i]].push_back(X[i]);
    }
    for(int i = 0; i < q; i++)
        req[L[i]].push_back(i);
    
    for(int i = n-1; i >= 0; i--) {
        for(int j : adj[i])
            if(j > i) {
                j = F(j);
                if(i != j) {
                    fils[i].push_back(j);
                    par[j] = i;
                }
            }
        for(int j : req[i])
            S[j] = F(S[j]);
        req[i].clear();
    }
    
    dfs(0);
    
    for(int i = 0; i < q; i++)
        req[R[i]].push_back(i);
    for(int i = 0; i < n; i++) {
        par[i] = i;
        vals[i].insert(deb[i]);
    }
    for(int i = 0; i < n; i++) {
        for(int j : adj[i])
            if(j < i)
                U(i, j);
        for(int j : req[i]) {
            auto it = vals[F(E[j])].lower_bound(deb[S[j]]);
            if(it != vals[F(E[j])].end() && (*it) < fin[S[j]])
                ans[j] = 1;
        }
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23892 KB Output is correct
2 Correct 13 ms 23800 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23768 KB Output is correct
5 Correct 11 ms 23800 KB Output is correct
6 Correct 12 ms 23784 KB Output is correct
7 Correct 12 ms 23816 KB Output is correct
8 Correct 11 ms 23836 KB Output is correct
9 Correct 13 ms 23740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23892 KB Output is correct
2 Correct 13 ms 23800 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23768 KB Output is correct
5 Correct 11 ms 23800 KB Output is correct
6 Correct 12 ms 23784 KB Output is correct
7 Correct 12 ms 23816 KB Output is correct
8 Correct 11 ms 23836 KB Output is correct
9 Correct 13 ms 23740 KB Output is correct
10 Correct 17 ms 24460 KB Output is correct
11 Correct 15 ms 24404 KB Output is correct
12 Correct 16 ms 24448 KB Output is correct
13 Correct 16 ms 24448 KB Output is correct
14 Correct 18 ms 24468 KB Output is correct
15 Correct 17 ms 24676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 624 ms 66080 KB Output is correct
2 Correct 413 ms 70480 KB Output is correct
3 Correct 428 ms 70088 KB Output is correct
4 Correct 489 ms 70052 KB Output is correct
5 Correct 494 ms 70224 KB Output is correct
6 Correct 576 ms 70692 KB Output is correct
7 Correct 638 ms 72136 KB Output is correct
8 Correct 409 ms 70480 KB Output is correct
9 Correct 370 ms 69508 KB Output is correct
10 Correct 420 ms 69652 KB Output is correct
11 Correct 427 ms 69748 KB Output is correct
12 Correct 524 ms 71180 KB Output is correct
13 Correct 449 ms 79352 KB Output is correct
14 Correct 426 ms 79408 KB Output is correct
15 Correct 466 ms 79336 KB Output is correct
16 Correct 474 ms 79304 KB Output is correct
17 Correct 662 ms 72168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23892 KB Output is correct
2 Correct 13 ms 23800 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23768 KB Output is correct
5 Correct 11 ms 23800 KB Output is correct
6 Correct 12 ms 23784 KB Output is correct
7 Correct 12 ms 23816 KB Output is correct
8 Correct 11 ms 23836 KB Output is correct
9 Correct 13 ms 23740 KB Output is correct
10 Correct 17 ms 24460 KB Output is correct
11 Correct 15 ms 24404 KB Output is correct
12 Correct 16 ms 24448 KB Output is correct
13 Correct 16 ms 24448 KB Output is correct
14 Correct 18 ms 24468 KB Output is correct
15 Correct 17 ms 24676 KB Output is correct
16 Correct 624 ms 66080 KB Output is correct
17 Correct 413 ms 70480 KB Output is correct
18 Correct 428 ms 70088 KB Output is correct
19 Correct 489 ms 70052 KB Output is correct
20 Correct 494 ms 70224 KB Output is correct
21 Correct 576 ms 70692 KB Output is correct
22 Correct 638 ms 72136 KB Output is correct
23 Correct 409 ms 70480 KB Output is correct
24 Correct 370 ms 69508 KB Output is correct
25 Correct 420 ms 69652 KB Output is correct
26 Correct 427 ms 69748 KB Output is correct
27 Correct 524 ms 71180 KB Output is correct
28 Correct 449 ms 79352 KB Output is correct
29 Correct 426 ms 79408 KB Output is correct
30 Correct 466 ms 79336 KB Output is correct
31 Correct 474 ms 79304 KB Output is correct
32 Correct 662 ms 72168 KB Output is correct
33 Correct 573 ms 70948 KB Output is correct
34 Correct 239 ms 56560 KB Output is correct
35 Correct 622 ms 72364 KB Output is correct
36 Correct 586 ms 70836 KB Output is correct
37 Correct 578 ms 71596 KB Output is correct
38 Correct 590 ms 71088 KB Output is correct
39 Correct 529 ms 69388 KB Output is correct
40 Correct 584 ms 81116 KB Output is correct
41 Correct 563 ms 71280 KB Output is correct
42 Correct 505 ms 70648 KB Output is correct
43 Correct 656 ms 76280 KB Output is correct
44 Correct 572 ms 71756 KB Output is correct
45 Correct 448 ms 69676 KB Output is correct
46 Correct 447 ms 69112 KB Output is correct
47 Correct 505 ms 79560 KB Output is correct
48 Correct 478 ms 79432 KB Output is correct
49 Correct 467 ms 79576 KB Output is correct
50 Correct 483 ms 79392 KB Output is correct
51 Correct 558 ms 80300 KB Output is correct
52 Correct 547 ms 80256 KB Output is correct