Submission #1104431

# Submission time Handle Problem Language Result Execution time Memory
1104431 2024-10-23T18:16:20 Z vivkostov Stranded Far From Home (BOI22_island) C++14
100 / 100
186 ms 42488 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
struct cell
{
    long long int st,in;
};
bool cmp(cell a1,cell a2)
{
    return a1.st<a2.st;
}
long long int n,m,l,r,lead[200005],sz[200005],lamp[200005],st[200005],otg[200005];
vector<int>valid[200005],v[200005];
cell a[200005];
void prec()
{
    for(int i=1;i<=n;i++)
    {
        lead[i]=i;
        sz[i]=1;
        st[i]=a[i].st;
        valid[i].push_back(i);
    }
}
int get_lead(int beg)
{
    if(lead[beg]==beg)return beg;
    return get_lead(lead[beg]);
}
void ad(int a,int b)
{
    a=get_lead(a);
    b=get_lead(b);
    if(a==b)return;
    if(sz[a]<sz[b])swap(a,b);
    lead[b]=lead[a];
    sz[a]+=sz[b];
    st[a]+=st[b];
    for(int i=0;i<valid[b].size();i++)
    {
        valid[a].push_back(valid[b][i]);
    }
}
void rem(int in,long long int tresh)
{
    in=get_lead(in);
    if(st[in]<tresh)
    {
        valid[in].clear();
    }
}
void add(int a,long long int tresh)
{
    lamp[a]=1;
    for(int i=0;i<v[a].size();i++)
    {
        if(lamp[v[a][i]])
        {
            rem(v[a][i],tresh);
            ad(a,v[a][i]);
        }
    }
}
void read()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].st;
        a[i].in=i;
    }
    for(int i=1;i<=m;i++)
    {
        cin>>l>>r;
        v[l].push_back(r);
        v[r].push_back(l);
    }
    prec();
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++)
    {
        add(a[i].in,a[i].st);
    }
    int f=get_lead(1);
    for(int i=0;i<valid[f].size();i++)
    {
        otg[valid[f][i]]=1;
    }
    for(int i=1;i<=n;i++)
    {
        cout<<otg[i];
    }
    cout<<endl;
}
int main()
{
    speed();
    read();
    return 0;
}

Compilation message

island.cpp: In function 'void ad(int, int)':
island.cpp:45:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i=0;i<valid[b].size();i++)
      |                 ~^~~~~~~~~~~~~~~~
island.cpp: In function 'void add(int, long long int)':
island.cpp:61:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for(int i=0;i<v[a].size();i++)
      |                 ~^~~~~~~~~~~~
island.cpp: In function 'void read()':
island.cpp:91:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     for(int i=0;i<valid[f].size();i++)
      |                 ~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16720 KB Output is correct
2 Correct 3 ms 16828 KB Output is correct
3 Correct 3 ms 16720 KB Output is correct
4 Correct 3 ms 16976 KB Output is correct
5 Correct 4 ms 17072 KB Output is correct
6 Correct 3 ms 16976 KB Output is correct
7 Correct 4 ms 16976 KB Output is correct
8 Correct 3 ms 16976 KB Output is correct
9 Correct 4 ms 17144 KB Output is correct
10 Correct 4 ms 16976 KB Output is correct
11 Correct 4 ms 16976 KB Output is correct
12 Correct 3 ms 16976 KB Output is correct
13 Correct 3 ms 16976 KB Output is correct
14 Correct 3 ms 16976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16720 KB Output is correct
2 Correct 2 ms 16720 KB Output is correct
3 Correct 94 ms 34496 KB Output is correct
4 Correct 130 ms 40380 KB Output is correct
5 Correct 115 ms 39880 KB Output is correct
6 Correct 117 ms 40896 KB Output is correct
7 Correct 145 ms 40800 KB Output is correct
8 Correct 131 ms 40008 KB Output is correct
9 Correct 112 ms 41924 KB Output is correct
10 Correct 87 ms 37820 KB Output is correct
11 Correct 109 ms 38844 KB Output is correct
12 Correct 138 ms 38188 KB Output is correct
13 Correct 112 ms 40892 KB Output is correct
14 Correct 107 ms 40380 KB Output is correct
15 Correct 98 ms 38856 KB Output is correct
16 Correct 73 ms 37824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 16720 KB Output is correct
2 Correct 164 ms 37028 KB Output is correct
3 Correct 152 ms 41536 KB Output is correct
4 Correct 123 ms 42488 KB Output is correct
5 Correct 104 ms 40892 KB Output is correct
6 Correct 163 ms 41544 KB Output is correct
7 Correct 124 ms 38792 KB Output is correct
8 Correct 115 ms 38848 KB Output is correct
9 Correct 77 ms 38032 KB Output is correct
10 Correct 97 ms 39112 KB Output is correct
11 Correct 108 ms 39600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16720 KB Output is correct
2 Correct 137 ms 34848 KB Output is correct
3 Correct 127 ms 39752 KB Output is correct
4 Correct 143 ms 40640 KB Output is correct
5 Correct 130 ms 41564 KB Output is correct
6 Correct 107 ms 39360 KB Output is correct
7 Correct 90 ms 39868 KB Output is correct
8 Correct 82 ms 38848 KB Output is correct
9 Correct 68 ms 30100 KB Output is correct
10 Correct 129 ms 41024 KB Output is correct
11 Correct 106 ms 39872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16720 KB Output is correct
2 Correct 3 ms 16828 KB Output is correct
3 Correct 3 ms 16720 KB Output is correct
4 Correct 3 ms 16976 KB Output is correct
5 Correct 4 ms 17072 KB Output is correct
6 Correct 3 ms 16976 KB Output is correct
7 Correct 4 ms 16976 KB Output is correct
8 Correct 3 ms 16976 KB Output is correct
9 Correct 4 ms 17144 KB Output is correct
10 Correct 4 ms 16976 KB Output is correct
11 Correct 4 ms 16976 KB Output is correct
12 Correct 3 ms 16976 KB Output is correct
13 Correct 3 ms 16976 KB Output is correct
14 Correct 3 ms 16976 KB Output is correct
15 Correct 3 ms 16720 KB Output is correct
16 Correct 2 ms 16720 KB Output is correct
17 Correct 94 ms 34496 KB Output is correct
18 Correct 130 ms 40380 KB Output is correct
19 Correct 115 ms 39880 KB Output is correct
20 Correct 117 ms 40896 KB Output is correct
21 Correct 145 ms 40800 KB Output is correct
22 Correct 131 ms 40008 KB Output is correct
23 Correct 112 ms 41924 KB Output is correct
24 Correct 87 ms 37820 KB Output is correct
25 Correct 109 ms 38844 KB Output is correct
26 Correct 138 ms 38188 KB Output is correct
27 Correct 112 ms 40892 KB Output is correct
28 Correct 107 ms 40380 KB Output is correct
29 Correct 98 ms 38856 KB Output is correct
30 Correct 73 ms 37824 KB Output is correct
31 Correct 4 ms 16720 KB Output is correct
32 Correct 164 ms 37028 KB Output is correct
33 Correct 152 ms 41536 KB Output is correct
34 Correct 123 ms 42488 KB Output is correct
35 Correct 104 ms 40892 KB Output is correct
36 Correct 163 ms 41544 KB Output is correct
37 Correct 124 ms 38792 KB Output is correct
38 Correct 115 ms 38848 KB Output is correct
39 Correct 77 ms 38032 KB Output is correct
40 Correct 97 ms 39112 KB Output is correct
41 Correct 108 ms 39600 KB Output is correct
42 Correct 3 ms 16720 KB Output is correct
43 Correct 137 ms 34848 KB Output is correct
44 Correct 127 ms 39752 KB Output is correct
45 Correct 143 ms 40640 KB Output is correct
46 Correct 130 ms 41564 KB Output is correct
47 Correct 107 ms 39360 KB Output is correct
48 Correct 90 ms 39868 KB Output is correct
49 Correct 82 ms 38848 KB Output is correct
50 Correct 68 ms 30100 KB Output is correct
51 Correct 129 ms 41024 KB Output is correct
52 Correct 106 ms 39872 KB Output is correct
53 Correct 3 ms 16720 KB Output is correct
54 Correct 3 ms 16720 KB Output is correct
55 Correct 3 ms 16720 KB Output is correct
56 Correct 4 ms 16988 KB Output is correct
57 Correct 4 ms 17116 KB Output is correct
58 Correct 4 ms 16976 KB Output is correct
59 Correct 3 ms 16884 KB Output is correct
60 Correct 3 ms 16976 KB Output is correct
61 Correct 3 ms 16976 KB Output is correct
62 Correct 4 ms 17024 KB Output is correct
63 Correct 5 ms 16976 KB Output is correct
64 Correct 4 ms 16888 KB Output is correct
65 Correct 3 ms 16976 KB Output is correct
66 Correct 3 ms 16976 KB Output is correct
67 Correct 90 ms 38792 KB Output is correct
68 Correct 96 ms 40204 KB Output is correct
69 Correct 121 ms 39880 KB Output is correct
70 Correct 129 ms 40720 KB Output is correct
71 Correct 123 ms 40548 KB Output is correct
72 Correct 117 ms 40004 KB Output is correct
73 Correct 115 ms 41828 KB Output is correct
74 Correct 79 ms 37844 KB Output is correct
75 Correct 101 ms 38852 KB Output is correct
76 Correct 132 ms 38128 KB Output is correct
77 Correct 121 ms 40652 KB Output is correct
78 Correct 101 ms 40380 KB Output is correct
79 Correct 98 ms 38740 KB Output is correct
80 Correct 74 ms 37760 KB Output is correct
81 Correct 152 ms 41468 KB Output is correct
82 Correct 151 ms 41536 KB Output is correct
83 Correct 121 ms 42484 KB Output is correct
84 Correct 108 ms 40892 KB Output is correct
85 Correct 186 ms 41544 KB Output is correct
86 Correct 141 ms 38860 KB Output is correct
87 Correct 159 ms 38716 KB Output is correct
88 Correct 128 ms 39108 KB Output is correct
89 Correct 144 ms 39764 KB Output is correct
90 Correct 125 ms 39284 KB Output is correct
91 Correct 140 ms 39752 KB Output is correct
92 Correct 127 ms 40640 KB Output is correct
93 Correct 128 ms 41664 KB Output is correct
94 Correct 138 ms 39360 KB Output is correct
95 Correct 90 ms 39868 KB Output is correct
96 Correct 81 ms 38848 KB Output is correct
97 Correct 77 ms 30096 KB Output is correct
98 Correct 144 ms 40900 KB Output is correct
99 Correct 122 ms 39832 KB Output is correct
100 Correct 29 ms 21072 KB Output is correct
101 Correct 129 ms 39920 KB Output is correct
102 Correct 88 ms 35588 KB Output is correct
103 Correct 111 ms 35728 KB Output is correct
104 Correct 136 ms 38756 KB Output is correct