Submission #1041244

# Submission time Handle Problem Language Result Execution time Memory
1041244 2024-08-01T19:37:18 Z Marco_Escandon Stranded Far From Home (BOI22_island) C++11
100 / 100
223 ms 45756 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define x first
#define y second
struct DSUF{
    vector<ll> P,S;
    vector<vector<ll>> E;
    ll Find(ll i){
        if(i==P[i]) return i;
        return P[i]=Find(P[i]);
    }
    void Union(ll a, ll b){
        a=Find(a);
        b=Find(b);
        if(a==b) return;
        if(S[a]<S[b])swap(a,b);
        S[a]+=S[b]; P[b]=a;
        for(auto i:E[b]) E[a].push_back(i);
    }
    bool Same(ll a, ll b) { return (Find(a)==Find(b)); }
    ll Size(ll a) { return S[a]; }
    DSUF(ll n,vector<ll> cad)
    {
        P.assign(n+5,0);
        S.assign(n+5,0);
        E.resize(n+5);
        for(int i=1; i<=n; i++)
            S[i]=cad[i];
        for(int i=0; i<P.size(); i++){
            P[i]=i;   
            E[i].push_back(i);
        }
    }
};
int main()
{
    ll n,m;
    cin>>n>>m;
    vector<ll> cad(n+1);
    vector<ll>sol(n+1,0);
    for(int i=1; i<=n; i++)
        cin>>cad[i];
    priority_queue<pair<ll,pair<ll,ll>>> q;
    for(int i=0; i<m; i++)
    {
        ll a,b;
        cin>>a>>b;
        if(cad[a]<cad[b]) swap(a,b);
        q.push({-cad[a],{a,b}});
    }
    DSUF asd(n,cad);
    while (!q.empty())
    {
        ll a=q.top().x;
        vector<pair<ll,ll>> temp;
        while(!q.empty()&&q.top().x==a){
            temp.push_back(q.top().y);
            q.pop();
        }
        for(int i=0; i<temp.size(); i++)
        {
            temp[i].x=asd.Find(temp[i].x);
            temp[i].y=asd.Find(temp[i].y);
        }
        sort(temp.begin(),temp.end());
        vector<pair<ll,ll>> temp2;temp2.push_back(temp[0]);
        for(int i=1; i<temp.size(); i++)
            if(temp[i]!=temp[i-1])
                temp2.push_back(temp[i]);
        for(auto i:temp2)
            if(asd.Size(i.y)<cad[i.x])
                asd.E[i.y].clear();
        for(auto i:temp2)
                asd.Union(i.x,i.y);
    }
    for(auto i:asd.E[asd.Find(1)])
        sol[i]=1;
        
    for(int i=1; i<=n; i++)
        cout<<sol[i];
    return 0;
}

Compilation message

island.cpp: In constructor 'DSUF::DSUF(ll, std::vector<long long int>)':
island.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for(int i=0; i<P.size(); i++){
      |                      ~^~~~~~~~~
island.cpp: In function 'int main()':
island.cpp:61:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         for(int i=0; i<temp.size(); i++)
      |                      ~^~~~~~~~~~~~
island.cpp:68:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         for(int i=1; i<temp.size(); i++)
      |                      ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 2 ms 544 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 1 ms 608 KB Output is correct
8 Correct 1 ms 608 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 700 KB Output is correct
14 Correct 1 ms 704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 164 ms 30420 KB Output is correct
4 Correct 144 ms 38076 KB Output is correct
5 Correct 161 ms 32636 KB Output is correct
6 Correct 171 ms 35000 KB Output is correct
7 Correct 168 ms 33656 KB Output is correct
8 Correct 163 ms 37836 KB Output is correct
9 Correct 157 ms 38028 KB Output is correct
10 Correct 132 ms 36796 KB Output is correct
11 Correct 132 ms 37308 KB Output is correct
12 Correct 135 ms 35012 KB Output is correct
13 Correct 121 ms 36024 KB Output is correct
14 Correct 128 ms 37812 KB Output is correct
15 Correct 153 ms 31540 KB Output is correct
16 Correct 121 ms 29996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 184 ms 36412 KB Output is correct
3 Correct 181 ms 36028 KB Output is correct
4 Correct 223 ms 38068 KB Output is correct
5 Correct 127 ms 39096 KB Output is correct
6 Correct 193 ms 35004 KB Output is correct
7 Correct 165 ms 32440 KB Output is correct
8 Correct 154 ms 31928 KB Output is correct
9 Correct 142 ms 30136 KB Output is correct
10 Correct 137 ms 37768 KB Output is correct
11 Correct 133 ms 31932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 168 ms 32600 KB Output is correct
3 Correct 165 ms 33716 KB Output is correct
4 Correct 164 ms 36536 KB Output is correct
5 Correct 171 ms 43324 KB Output is correct
6 Correct 173 ms 38588 KB Output is correct
7 Correct 169 ms 37708 KB Output is correct
8 Correct 134 ms 33464 KB Output is correct
9 Correct 116 ms 19192 KB Output is correct
10 Correct 146 ms 42424 KB Output is correct
11 Correct 138 ms 31668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 2 ms 544 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 1 ms 608 KB Output is correct
8 Correct 1 ms 608 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 700 KB Output is correct
14 Correct 1 ms 704 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 164 ms 30420 KB Output is correct
18 Correct 144 ms 38076 KB Output is correct
19 Correct 161 ms 32636 KB Output is correct
20 Correct 171 ms 35000 KB Output is correct
21 Correct 168 ms 33656 KB Output is correct
22 Correct 163 ms 37836 KB Output is correct
23 Correct 157 ms 38028 KB Output is correct
24 Correct 132 ms 36796 KB Output is correct
25 Correct 132 ms 37308 KB Output is correct
26 Correct 135 ms 35012 KB Output is correct
27 Correct 121 ms 36024 KB Output is correct
28 Correct 128 ms 37812 KB Output is correct
29 Correct 153 ms 31540 KB Output is correct
30 Correct 121 ms 29996 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 184 ms 36412 KB Output is correct
33 Correct 181 ms 36028 KB Output is correct
34 Correct 223 ms 38068 KB Output is correct
35 Correct 127 ms 39096 KB Output is correct
36 Correct 193 ms 35004 KB Output is correct
37 Correct 165 ms 32440 KB Output is correct
38 Correct 154 ms 31928 KB Output is correct
39 Correct 142 ms 30136 KB Output is correct
40 Correct 137 ms 37768 KB Output is correct
41 Correct 133 ms 31932 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 168 ms 32600 KB Output is correct
44 Correct 165 ms 33716 KB Output is correct
45 Correct 164 ms 36536 KB Output is correct
46 Correct 171 ms 43324 KB Output is correct
47 Correct 173 ms 38588 KB Output is correct
48 Correct 169 ms 37708 KB Output is correct
49 Correct 134 ms 33464 KB Output is correct
50 Correct 116 ms 19192 KB Output is correct
51 Correct 146 ms 42424 KB Output is correct
52 Correct 138 ms 31668 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Correct 0 ms 344 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 2 ms 600 KB Output is correct
57 Correct 2 ms 604 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
59 Correct 2 ms 604 KB Output is correct
60 Correct 1 ms 600 KB Output is correct
61 Correct 1 ms 604 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 2 ms 704 KB Output is correct
64 Correct 2 ms 604 KB Output is correct
65 Correct 2 ms 608 KB Output is correct
66 Correct 2 ms 740 KB Output is correct
67 Correct 156 ms 31724 KB Output is correct
68 Correct 128 ms 35516 KB Output is correct
69 Correct 169 ms 33460 KB Output is correct
70 Correct 162 ms 33972 KB Output is correct
71 Correct 163 ms 33976 KB Output is correct
72 Correct 158 ms 39092 KB Output is correct
73 Correct 157 ms 39352 KB Output is correct
74 Correct 135 ms 37560 KB Output is correct
75 Correct 133 ms 39868 KB Output is correct
76 Correct 137 ms 35496 KB Output is correct
77 Correct 123 ms 36284 KB Output is correct
78 Correct 126 ms 35584 KB Output is correct
79 Correct 152 ms 32308 KB Output is correct
80 Correct 130 ms 30136 KB Output is correct
81 Correct 176 ms 36536 KB Output is correct
82 Correct 178 ms 35912 KB Output is correct
83 Correct 163 ms 37564 KB Output is correct
84 Correct 122 ms 37560 KB Output is correct
85 Correct 183 ms 35648 KB Output is correct
86 Correct 154 ms 31164 KB Output is correct
87 Correct 169 ms 32456 KB Output is correct
88 Correct 136 ms 36920 KB Output is correct
89 Correct 130 ms 30904 KB Output is correct
90 Correct 187 ms 33080 KB Output is correct
91 Correct 172 ms 34088 KB Output is correct
92 Correct 171 ms 36280 KB Output is correct
93 Correct 172 ms 45756 KB Output is correct
94 Correct 191 ms 40892 KB Output is correct
95 Correct 178 ms 37560 KB Output is correct
96 Correct 125 ms 32440 KB Output is correct
97 Correct 111 ms 20152 KB Output is correct
98 Correct 142 ms 43448 KB Output is correct
99 Correct 133 ms 30960 KB Output is correct
100 Correct 85 ms 9412 KB Output is correct
101 Correct 172 ms 31928 KB Output is correct
102 Correct 160 ms 35252 KB Output is correct
103 Correct 160 ms 26176 KB Output is correct
104 Correct 166 ms 29628 KB Output is correct