답안 #646779

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
646779 2022-09-30T15:41:07 Z Tenis0206 Stranded Far From Home (BOI22_island) C++11
100 / 100
258 ms 43172 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

int n,m;
int s[200005];

vector<int> G[200005];

bool ok[200005];

int t[200005],sum[200005];

vector<int> l[200005];

int p[200005];

int reprezentant(int nod)
{
    if(t[nod]==nod)
    {
        return t[nod];
    }
    return t[nod] = reprezentant(t[nod]);
}

void uneste(int x, int y)
{
   x = reprezentant(x);
   y = reprezentant(y);
   if(x==y)
   {
       return;
   }
   if(l[x].size() > l[y].size())
   {
        t[y] = x;
        sum[x] += sum[y];
        for(auto it : l[y])
        {
            l[x].push_back(it);
        }
   }
   else
   {
        t[x] = y;
        sum[y] += sum[x];
        for(auto it : l[x])
        {
            l[y].push_back(it);
        }
   }
}

bool cmp(int a, int b)
{
    return s[a] < s[b];
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifdef home
    freopen("nr.in","r",stdin);
    freopen("nr.out","w",stdout);
    #endif // home
    cin>>n>>m;
    for(int i=1; i<=n; i++)
    {
        cin>>s[i];
        p[i] = i;
    }
    for(int i=1; i<=m; i++)
    {
        int x,y;
        cin>>x>>y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    for(int i=1; i<=n; i++)
    {
        t[i] = i;
        l[i].push_back(i);
        sum[i] = s[i];
        ok[i] = true;
    }
    sort(p+1,p+n+1,cmp);
    for(int i=1;i<=n;i++)
    {
        int nod = p[i];
        for(auto it : G[nod])
        {
            if(s[it] > s[nod])
            {
                continue;
            }
            if(sum[reprezentant(it)] >= s[nod])
            {
                uneste(nod,it);
            }
            else
            {
                for(auto e : l[reprezentant(it)])
                {
                    ok[e] = false;
                }
                l[reprezentant(it)].clear();
                uneste(nod,it);
            }
        }
    }
    for(int i=1; i<=n; i++)
    {
        cout<<ok[i];
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9688 KB Output is correct
3 Correct 5 ms 9732 KB Output is correct
4 Correct 6 ms 9856 KB Output is correct
5 Correct 6 ms 9940 KB Output is correct
6 Correct 6 ms 9940 KB Output is correct
7 Correct 6 ms 9812 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 7 ms 9880 KB Output is correct
10 Correct 8 ms 9920 KB Output is correct
11 Correct 8 ms 9940 KB Output is correct
12 Correct 6 ms 9940 KB Output is correct
13 Correct 6 ms 9940 KB Output is correct
14 Correct 7 ms 9980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 147 ms 32120 KB Output is correct
4 Correct 163 ms 37712 KB Output is correct
5 Correct 203 ms 34404 KB Output is correct
6 Correct 203 ms 39824 KB Output is correct
7 Correct 193 ms 39744 KB Output is correct
8 Correct 246 ms 39936 KB Output is correct
9 Correct 165 ms 43172 KB Output is correct
10 Correct 146 ms 33976 KB Output is correct
11 Correct 122 ms 36652 KB Output is correct
12 Correct 238 ms 36756 KB Output is correct
13 Correct 160 ms 40676 KB Output is correct
14 Correct 145 ms 40116 KB Output is correct
15 Correct 145 ms 35412 KB Output is correct
16 Correct 106 ms 34316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 213 ms 35980 KB Output is correct
3 Correct 216 ms 40712 KB Output is correct
4 Correct 170 ms 42348 KB Output is correct
5 Correct 176 ms 40996 KB Output is correct
6 Correct 215 ms 40476 KB Output is correct
7 Correct 184 ms 35232 KB Output is correct
8 Correct 215 ms 35316 KB Output is correct
9 Correct 99 ms 34376 KB Output is correct
10 Correct 165 ms 36464 KB Output is correct
11 Correct 187 ms 38612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 246 ms 32848 KB Output is correct
3 Correct 230 ms 33708 KB Output is correct
4 Correct 230 ms 35224 KB Output is correct
5 Correct 239 ms 37764 KB Output is correct
6 Correct 224 ms 34164 KB Output is correct
7 Correct 124 ms 33360 KB Output is correct
8 Correct 107 ms 36324 KB Output is correct
9 Correct 151 ms 23232 KB Output is correct
10 Correct 222 ms 41840 KB Output is correct
11 Correct 182 ms 38880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9688 KB Output is correct
3 Correct 5 ms 9732 KB Output is correct
4 Correct 6 ms 9856 KB Output is correct
5 Correct 6 ms 9940 KB Output is correct
6 Correct 6 ms 9940 KB Output is correct
7 Correct 6 ms 9812 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 7 ms 9880 KB Output is correct
10 Correct 8 ms 9920 KB Output is correct
11 Correct 8 ms 9940 KB Output is correct
12 Correct 6 ms 9940 KB Output is correct
13 Correct 6 ms 9940 KB Output is correct
14 Correct 7 ms 9980 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 147 ms 32120 KB Output is correct
18 Correct 163 ms 37712 KB Output is correct
19 Correct 203 ms 34404 KB Output is correct
20 Correct 203 ms 39824 KB Output is correct
21 Correct 193 ms 39744 KB Output is correct
22 Correct 246 ms 39936 KB Output is correct
23 Correct 165 ms 43172 KB Output is correct
24 Correct 146 ms 33976 KB Output is correct
25 Correct 122 ms 36652 KB Output is correct
26 Correct 238 ms 36756 KB Output is correct
27 Correct 160 ms 40676 KB Output is correct
28 Correct 145 ms 40116 KB Output is correct
29 Correct 145 ms 35412 KB Output is correct
30 Correct 106 ms 34316 KB Output is correct
31 Correct 6 ms 9684 KB Output is correct
32 Correct 213 ms 35980 KB Output is correct
33 Correct 216 ms 40712 KB Output is correct
34 Correct 170 ms 42348 KB Output is correct
35 Correct 176 ms 40996 KB Output is correct
36 Correct 215 ms 40476 KB Output is correct
37 Correct 184 ms 35232 KB Output is correct
38 Correct 215 ms 35316 KB Output is correct
39 Correct 99 ms 34376 KB Output is correct
40 Correct 165 ms 36464 KB Output is correct
41 Correct 187 ms 38612 KB Output is correct
42 Correct 5 ms 9684 KB Output is correct
43 Correct 246 ms 32848 KB Output is correct
44 Correct 230 ms 33708 KB Output is correct
45 Correct 230 ms 35224 KB Output is correct
46 Correct 239 ms 37764 KB Output is correct
47 Correct 224 ms 34164 KB Output is correct
48 Correct 124 ms 33360 KB Output is correct
49 Correct 107 ms 36324 KB Output is correct
50 Correct 151 ms 23232 KB Output is correct
51 Correct 222 ms 41840 KB Output is correct
52 Correct 182 ms 38880 KB Output is correct
53 Correct 5 ms 9616 KB Output is correct
54 Correct 5 ms 9684 KB Output is correct
55 Correct 5 ms 9684 KB Output is correct
56 Correct 6 ms 9940 KB Output is correct
57 Correct 7 ms 9940 KB Output is correct
58 Correct 7 ms 9940 KB Output is correct
59 Correct 7 ms 9972 KB Output is correct
60 Correct 6 ms 9812 KB Output is correct
61 Correct 6 ms 9996 KB Output is correct
62 Correct 7 ms 9996 KB Output is correct
63 Correct 7 ms 9904 KB Output is correct
64 Correct 7 ms 9948 KB Output is correct
65 Correct 8 ms 9940 KB Output is correct
66 Correct 6 ms 9940 KB Output is correct
67 Correct 155 ms 36596 KB Output is correct
68 Correct 160 ms 40728 KB Output is correct
69 Correct 188 ms 38832 KB Output is correct
70 Correct 216 ms 39904 KB Output is correct
71 Correct 184 ms 39676 KB Output is correct
72 Correct 218 ms 39956 KB Output is correct
73 Correct 201 ms 43112 KB Output is correct
74 Correct 156 ms 33956 KB Output is correct
75 Correct 127 ms 36664 KB Output is correct
76 Correct 229 ms 36848 KB Output is correct
77 Correct 153 ms 40596 KB Output is correct
78 Correct 153 ms 40148 KB Output is correct
79 Correct 151 ms 35276 KB Output is correct
80 Correct 107 ms 34364 KB Output is correct
81 Correct 247 ms 40292 KB Output is correct
82 Correct 217 ms 40720 KB Output is correct
83 Correct 181 ms 42260 KB Output is correct
84 Correct 152 ms 41016 KB Output is correct
85 Correct 216 ms 40448 KB Output is correct
86 Correct 168 ms 35312 KB Output is correct
87 Correct 181 ms 35344 KB Output is correct
88 Correct 184 ms 36444 KB Output is correct
89 Correct 177 ms 38544 KB Output is correct
90 Correct 228 ms 37232 KB Output is correct
91 Correct 258 ms 38036 KB Output is correct
92 Correct 235 ms 39668 KB Output is correct
93 Correct 238 ms 42320 KB Output is correct
94 Correct 197 ms 38456 KB Output is correct
95 Correct 146 ms 37608 KB Output is correct
96 Correct 120 ms 39664 KB Output is correct
97 Correct 108 ms 25804 KB Output is correct
98 Correct 206 ms 41864 KB Output is correct
99 Correct 183 ms 38936 KB Output is correct
100 Correct 43 ms 16292 KB Output is correct
101 Correct 232 ms 38440 KB Output is correct
102 Correct 168 ms 33880 KB Output is correct
103 Correct 197 ms 32620 KB Output is correct
104 Correct 232 ms 36272 KB Output is correct