답안 #1105004

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1105004 2024-10-25T06:50:11 Z MateiKing80 Stranded Far From Home (BOI22_island) C++14
100 / 100
243 ms 44184 KB
#include <bits/stdc++.h>

using namespace std;

int papa(int u, vector<int> &p)
{
    if(p[u] < 0)
        return u;
    return p[u] = papa(p[u], p);
}

void unite(int u, int v, vector<int> &p, vector<long long> &put)
{
    u = papa(u,p), v = papa(v,p);
    if(u == v)
        return;
    if(p[u] > p[v])
        swap(u,v);
    p[u] += p[v];
    p[v] = u;
    put[u] += put[v];
}

void dfs(int u, int sus, vector<int> &castig, vector<vector<int>> &ok)
{
    castig[u] &= sus;
    for(int v : ok[u])
        dfs(v, castig[u], castig, ok);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> s(n);
    for(int &x : s)
        cin >> x;
    vector<vector<int>> g(n);
    for(int i = 0, u, v; i < m; i ++)
    {
        cin >> u >> v;
        u--, v--;
        g[u].push_back(v), g[v].push_back(u);
    }
    vector<int> castig(n, 1), p(n, -1), viz(n), ins(n), rep(n);
    vector<long long> put(n);
    vector<vector<int>> ok(n);
    vector<pair<int,int>> order(n);
    for(int i = 0; i < n; i ++)
    {
        put[i] = s[i];
        order[i] = {s[i], i};
    }
    sort(order.begin(), order.end());
    for(auto t : order)
    {
        int u = t.second;
        for(int v : g[u])
            if(ins[v])
            {
                int w = rep[papa(v,p)];
                if(put[papa(v,p)] < s[u])
                    castig[w] = 0;
                if(!viz[w])
                {
                    ok[u].push_back(w);
                    viz[w] = 1;
                }
            }
        for(int v : g[u])
            if(ins[v])
                viz[rep[papa(v,p)]] = 0;
        for(int v : g[u])
            if(ins[v])
                unite(u, v, p, put);
        rep[papa(u,p)] = u;
        ins[u] = 1;
    }
    dfs(order[n - 1].second, 1, castig, ok);
    for(int i = 0; i < n; i ++)
        cout << castig[i];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 764 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 760 KB Output is correct
9 Correct 2 ms 1016 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 2 ms 848 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 122 ms 35912 KB Output is correct
4 Correct 140 ms 40644 KB Output is correct
5 Correct 118 ms 29408 KB Output is correct
6 Correct 130 ms 31816 KB Output is correct
7 Correct 118 ms 32520 KB Output is correct
8 Correct 123 ms 42328 KB Output is correct
9 Correct 127 ms 29512 KB Output is correct
10 Correct 101 ms 28256 KB Output is correct
11 Correct 130 ms 42488 KB Output is correct
12 Correct 137 ms 33732 KB Output is correct
13 Correct 111 ms 41544 KB Output is correct
14 Correct 135 ms 41800 KB Output is correct
15 Correct 145 ms 44104 KB Output is correct
16 Correct 100 ms 43108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 154 ms 32480 KB Output is correct
3 Correct 153 ms 32580 KB Output is correct
4 Correct 143 ms 44104 KB Output is correct
5 Correct 113 ms 38472 KB Output is correct
6 Correct 163 ms 32584 KB Output is correct
7 Correct 147 ms 44104 KB Output is correct
8 Correct 161 ms 44184 KB Output is correct
9 Correct 87 ms 43080 KB Output is correct
10 Correct 122 ms 35588 KB Output is correct
11 Correct 145 ms 31788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 187 ms 31256 KB Output is correct
3 Correct 196 ms 32576 KB Output is correct
4 Correct 221 ms 32664 KB Output is correct
5 Correct 182 ms 32580 KB Output is correct
6 Correct 167 ms 32328 KB Output is correct
7 Correct 112 ms 36440 KB Output is correct
8 Correct 85 ms 42848 KB Output is correct
9 Correct 86 ms 18604 KB Output is correct
10 Correct 121 ms 31092 KB Output is correct
11 Correct 119 ms 31660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 764 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 760 KB Output is correct
9 Correct 2 ms 1016 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 2 ms 848 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 122 ms 35912 KB Output is correct
18 Correct 140 ms 40644 KB Output is correct
19 Correct 118 ms 29408 KB Output is correct
20 Correct 130 ms 31816 KB Output is correct
21 Correct 118 ms 32520 KB Output is correct
22 Correct 123 ms 42328 KB Output is correct
23 Correct 127 ms 29512 KB Output is correct
24 Correct 101 ms 28256 KB Output is correct
25 Correct 130 ms 42488 KB Output is correct
26 Correct 137 ms 33732 KB Output is correct
27 Correct 111 ms 41544 KB Output is correct
28 Correct 135 ms 41800 KB Output is correct
29 Correct 145 ms 44104 KB Output is correct
30 Correct 100 ms 43108 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 154 ms 32480 KB Output is correct
33 Correct 153 ms 32580 KB Output is correct
34 Correct 143 ms 44104 KB Output is correct
35 Correct 113 ms 38472 KB Output is correct
36 Correct 163 ms 32584 KB Output is correct
37 Correct 147 ms 44104 KB Output is correct
38 Correct 161 ms 44184 KB Output is correct
39 Correct 87 ms 43080 KB Output is correct
40 Correct 122 ms 35588 KB Output is correct
41 Correct 145 ms 31788 KB Output is correct
42 Correct 1 ms 504 KB Output is correct
43 Correct 187 ms 31256 KB Output is correct
44 Correct 196 ms 32576 KB Output is correct
45 Correct 221 ms 32664 KB Output is correct
46 Correct 182 ms 32580 KB Output is correct
47 Correct 167 ms 32328 KB Output is correct
48 Correct 112 ms 36440 KB Output is correct
49 Correct 85 ms 42848 KB Output is correct
50 Correct 86 ms 18604 KB Output is correct
51 Correct 121 ms 31092 KB Output is correct
52 Correct 119 ms 31660 KB Output is correct
53 Correct 1 ms 336 KB Output is correct
54 Correct 1 ms 396 KB Output is correct
55 Correct 1 ms 504 KB Output is correct
56 Correct 2 ms 504 KB Output is correct
57 Correct 2 ms 592 KB Output is correct
58 Correct 2 ms 592 KB Output is correct
59 Correct 2 ms 592 KB Output is correct
60 Correct 1 ms 592 KB Output is correct
61 Correct 1 ms 724 KB Output is correct
62 Correct 2 ms 592 KB Output is correct
63 Correct 2 ms 592 KB Output is correct
64 Correct 1 ms 592 KB Output is correct
65 Correct 2 ms 848 KB Output is correct
66 Correct 2 ms 592 KB Output is correct
67 Correct 117 ms 36536 KB Output is correct
68 Correct 107 ms 41800 KB Output is correct
69 Correct 113 ms 31400 KB Output is correct
70 Correct 117 ms 32336 KB Output is correct
71 Correct 115 ms 30544 KB Output is correct
72 Correct 146 ms 42180 KB Output is correct
73 Correct 108 ms 29512 KB Output is correct
74 Correct 84 ms 28232 KB Output is correct
75 Correct 116 ms 43904 KB Output is correct
76 Correct 146 ms 33616 KB Output is correct
77 Correct 118 ms 42580 KB Output is correct
78 Correct 128 ms 41708 KB Output is correct
79 Correct 110 ms 44104 KB Output is correct
80 Correct 86 ms 42944 KB Output is correct
81 Correct 154 ms 32428 KB Output is correct
82 Correct 174 ms 32572 KB Output is correct
83 Correct 143 ms 44156 KB Output is correct
84 Correct 142 ms 39496 KB Output is correct
85 Correct 167 ms 32588 KB Output is correct
86 Correct 141 ms 42312 KB Output is correct
87 Correct 243 ms 44056 KB Output is correct
88 Correct 105 ms 35656 KB Output is correct
89 Correct 124 ms 32840 KB Output is correct
90 Correct 202 ms 32824 KB Output is correct
91 Correct 167 ms 32376 KB Output is correct
92 Correct 168 ms 32544 KB Output is correct
93 Correct 155 ms 32584 KB Output is correct
94 Correct 172 ms 32220 KB Output is correct
95 Correct 139 ms 36472 KB Output is correct
96 Correct 96 ms 43080 KB Output is correct
97 Correct 89 ms 18508 KB Output is correct
98 Correct 117 ms 31048 KB Output is correct
99 Correct 146 ms 32856 KB Output is correct
100 Correct 39 ms 4988 KB Output is correct
101 Correct 185 ms 32684 KB Output is correct
102 Correct 142 ms 29000 KB Output is correct
103 Correct 173 ms 30324 KB Output is correct
104 Correct 176 ms 33008 KB Output is correct