답안 #573319

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
573319 2022-06-06T12:05:18 Z MohamedAliSaidane Stranded Far From Home (BOI22_island) C++14
100 / 100
198 ms 20088 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

        using namespace __gnu_pbds;
        using namespace std;

        typedef tree<int,null_type,less<int>,rb_tree_tag,
        tree_order_statistics_node_update> indexed_set;

        typedef long long ll;
        typedef long double ld;

        typedef pair<int,int> pii;
        typedef pair<ll,ll> pll;
        typedef pair<ld,ld> pld;

        typedef vector<int> vi;
        typedef vector<ll> vll;
        typedef vector<pii> vpi;
        typedef vector<pll> vpl;

        #define pb push_back
        #define popb pop_back
        #define pp pop_back
        #define pf push_front
        #define popf pop_front
        #define all(x) (x).begin(),(x).end()
        #define ff first
        #define ss second

        ///#define int ll

        int nx[4] = {0,0,1,-1}, ny[4] = {1,-1,0,0};
        ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;}
        ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);}

        const int nax = 2e5 + 4;
        int p[nax];
        int ans[nax];
        int n, m;
        ll s[nax];
        ll val[nax];
        vi adj[nax];
        vpl edges;
        int findset(int x, ll v)
        {
            int head = p[x] == x? x: findset(p[x],v);
            if(ans[p[x]] == 0)
                ans[x] =0;
            if(s[head] < v)
                ans[x] = 0;
            return p[x] = head;
        }
        void unite(int i, int j, ll v)
        {
            int x = findset(i,v);
            int y = findset(j,v);
            if(x == y)
                return ;
            if(s[x] > s[y])
                swap(x,y);
            p[x] = y;
            s[y] += s[x];
        }

        bool comp(pll a, pll b)
        {
            ll u = max(val[a.ff],val[a.ss]);
            ll v = max(val[b.ff],val[b.ss]);
            return u < v;
        }
        void solve()
        {

            cin >> n >> m;
            for(int i = 1; i <= n; i++)
            {
                cin >> s[i];
                val[i] = s[i];
                p[i] = i;
                ans[i] = 1;
            }
            for(int i = 1; i <= m; i ++)
            {
                int a, b;
                cin >> a >> b;
                adj[a].pb(b);
                adj[b].pb(a);
                edges.pb({a,b});
            }
            sort(all(edges),comp);
            for(auto e: edges)
            {
                ll maxi = max(val[e.ff],val[e.ss]);
                unite(e.ff,e.ss,maxi);
            }
            ll tot = 0ll;
            for(int i = 1; i <= n; i++)
                tot += val[i];
            for(int i = 1; i <= n; i++)
            {
                int x = findset(i,0);
                if(ans[i] == 0)
                    cout << 0;
                else if(s[x] < tot)
                    cout << 0;
                else
                    cout << 1;
            }
        }

        int32_t main()
        {
            ios::sync_with_stdio(false);
            cin.tie(0); cout.tie(0);
            int tt = 1;
            while(tt --)
                solve();
        }


# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5180 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 5 ms 5076 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 5 ms 5076 KB Output is correct
13 Correct 5 ms 5076 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 144 ms 19320 KB Output is correct
4 Correct 137 ms 19308 KB Output is correct
5 Correct 151 ms 18860 KB Output is correct
6 Correct 165 ms 19244 KB Output is correct
7 Correct 176 ms 19252 KB Output is correct
8 Correct 155 ms 19300 KB Output is correct
9 Correct 152 ms 19240 KB Output is correct
10 Correct 127 ms 20016 KB Output is correct
11 Correct 117 ms 20056 KB Output is correct
12 Correct 142 ms 19292 KB Output is correct
13 Correct 143 ms 19336 KB Output is correct
14 Correct 123 ms 19332 KB Output is correct
15 Correct 154 ms 19256 KB Output is correct
16 Correct 91 ms 19124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 156 ms 19376 KB Output is correct
3 Correct 172 ms 19328 KB Output is correct
4 Correct 135 ms 19260 KB Output is correct
5 Correct 119 ms 19304 KB Output is correct
6 Correct 183 ms 19352 KB Output is correct
7 Correct 171 ms 19316 KB Output is correct
8 Correct 150 ms 19304 KB Output is correct
9 Correct 97 ms 19100 KB Output is correct
10 Correct 135 ms 19300 KB Output is correct
11 Correct 144 ms 19300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 164 ms 19340 KB Output is correct
3 Correct 158 ms 19212 KB Output is correct
4 Correct 196 ms 19300 KB Output is correct
5 Correct 159 ms 19332 KB Output is correct
6 Correct 142 ms 18768 KB Output is correct
7 Correct 126 ms 20044 KB Output is correct
8 Correct 121 ms 19268 KB Output is correct
9 Correct 106 ms 14732 KB Output is correct
10 Correct 149 ms 19472 KB Output is correct
11 Correct 121 ms 19256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5180 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 5 ms 5076 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 5 ms 5076 KB Output is correct
13 Correct 5 ms 5076 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 144 ms 19320 KB Output is correct
18 Correct 137 ms 19308 KB Output is correct
19 Correct 151 ms 18860 KB Output is correct
20 Correct 165 ms 19244 KB Output is correct
21 Correct 176 ms 19252 KB Output is correct
22 Correct 155 ms 19300 KB Output is correct
23 Correct 152 ms 19240 KB Output is correct
24 Correct 127 ms 20016 KB Output is correct
25 Correct 117 ms 20056 KB Output is correct
26 Correct 142 ms 19292 KB Output is correct
27 Correct 143 ms 19336 KB Output is correct
28 Correct 123 ms 19332 KB Output is correct
29 Correct 154 ms 19256 KB Output is correct
30 Correct 91 ms 19124 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 156 ms 19376 KB Output is correct
33 Correct 172 ms 19328 KB Output is correct
34 Correct 135 ms 19260 KB Output is correct
35 Correct 119 ms 19304 KB Output is correct
36 Correct 183 ms 19352 KB Output is correct
37 Correct 171 ms 19316 KB Output is correct
38 Correct 150 ms 19304 KB Output is correct
39 Correct 97 ms 19100 KB Output is correct
40 Correct 135 ms 19300 KB Output is correct
41 Correct 144 ms 19300 KB Output is correct
42 Correct 2 ms 4948 KB Output is correct
43 Correct 164 ms 19340 KB Output is correct
44 Correct 158 ms 19212 KB Output is correct
45 Correct 196 ms 19300 KB Output is correct
46 Correct 159 ms 19332 KB Output is correct
47 Correct 142 ms 18768 KB Output is correct
48 Correct 126 ms 20044 KB Output is correct
49 Correct 121 ms 19268 KB Output is correct
50 Correct 106 ms 14732 KB Output is correct
51 Correct 149 ms 19472 KB Output is correct
52 Correct 121 ms 19256 KB Output is correct
53 Correct 2 ms 4948 KB Output is correct
54 Correct 2 ms 4964 KB Output is correct
55 Correct 2 ms 4948 KB Output is correct
56 Correct 3 ms 5136 KB Output is correct
57 Correct 4 ms 5076 KB Output is correct
58 Correct 4 ms 5080 KB Output is correct
59 Correct 4 ms 5076 KB Output is correct
60 Correct 4 ms 5076 KB Output is correct
61 Correct 3 ms 5076 KB Output is correct
62 Correct 5 ms 5076 KB Output is correct
63 Correct 4 ms 5076 KB Output is correct
64 Correct 4 ms 5076 KB Output is correct
65 Correct 4 ms 5076 KB Output is correct
66 Correct 3 ms 5076 KB Output is correct
67 Correct 144 ms 19312 KB Output is correct
68 Correct 122 ms 19196 KB Output is correct
69 Correct 156 ms 18800 KB Output is correct
70 Correct 167 ms 19432 KB Output is correct
71 Correct 150 ms 19248 KB Output is correct
72 Correct 134 ms 19256 KB Output is correct
73 Correct 153 ms 19224 KB Output is correct
74 Correct 132 ms 20072 KB Output is correct
75 Correct 142 ms 20084 KB Output is correct
76 Correct 145 ms 19296 KB Output is correct
77 Correct 126 ms 19324 KB Output is correct
78 Correct 141 ms 19328 KB Output is correct
79 Correct 179 ms 19276 KB Output is correct
80 Correct 86 ms 19120 KB Output is correct
81 Correct 153 ms 19272 KB Output is correct
82 Correct 174 ms 19492 KB Output is correct
83 Correct 145 ms 19220 KB Output is correct
84 Correct 138 ms 19252 KB Output is correct
85 Correct 150 ms 19228 KB Output is correct
86 Correct 147 ms 19320 KB Output is correct
87 Correct 185 ms 19284 KB Output is correct
88 Correct 136 ms 19256 KB Output is correct
89 Correct 126 ms 19272 KB Output is correct
90 Correct 159 ms 19264 KB Output is correct
91 Correct 171 ms 19248 KB Output is correct
92 Correct 158 ms 19288 KB Output is correct
93 Correct 143 ms 19416 KB Output is correct
94 Correct 151 ms 18736 KB Output is correct
95 Correct 111 ms 20088 KB Output is correct
96 Correct 92 ms 19280 KB Output is correct
97 Correct 133 ms 14696 KB Output is correct
98 Correct 137 ms 19352 KB Output is correct
99 Correct 131 ms 19400 KB Output is correct
100 Correct 72 ms 11088 KB Output is correct
101 Correct 198 ms 19316 KB Output is correct
102 Correct 124 ms 17044 KB Output is correct
103 Correct 166 ms 17592 KB Output is correct
104 Correct 167 ms 19132 KB Output is correct