답안 #599753

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
599753 2022-07-19T20:23:58 Z Mounir Stranded Far From Home (BOI22_island) C++14
100 / 100
305 ms 65840 KB
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define chmax(x, v) x = max(x, v)
#define chmin(x, v) x = min(x, v)
#define pb push_back
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define x first
#define y second
#define int long long
using namespace std;
 
const int N = 3e5;
int sousArbre[N];
vector<int> enfants[N];
vector<int> winner[N];
int vals[N];
 
void dfs(int noeud){
      sousArbre[noeud] = vals[noeud];
      for (int enfant : enfants[noeud]){
            dfs(enfant);
            sousArbre[noeud] += sousArbre[enfant];
            if (sousArbre[enfant] >= vals[noeud])
                  winner[noeud].pb(enfant);
      }
}
 
bool vainqueur[N];
void complete(int noeud){
      vainqueur[noeud] = true;
      for (int enf : winner[noeud])
            complete(enf);
}
 
struct Noeud {
      int noeud, val;
 
      bool operator < (const Noeud &autre) const {
            if (val != autre.val)
                  return val < autre.val;
            return noeud < autre.noeud;
      }
};
 
vector<int> voisins[N];
int ens[N];
int getEns(int noeud){
      if (ens[noeud] != noeud)
            ens[noeud] = getEns(ens[noeud]);
      return ens[noeud];
}
 
 
signed main(){ 
      ios::sync_with_stdio(false);
      cin.tie(nullptr);
      int nNoeuds, nAretes; cin >> nNoeuds >> nAretes;
      for (int noeud = 0; noeud < nNoeuds; ++noeud)
            ens[noeud] = noeud;
      for (int i = 0; i < nNoeuds; ++i)
            cin >> vals[i];
      for (int i = 0; i < nAretes; ++i){
            int u, v; cin >> u >> v;
            u--; v--;
            voisins[u].pb(v);
            voisins[v].pb(u);
      }
 
      vector<Noeud> sac;
      for (int noeud = 0; noeud < nNoeuds; ++noeud)
            sac.pb({noeud, vals[noeud]});
      sort(all(sac));
      int root = -1;    
      for (Noeud nod : sac){
            int noeud = nod.noeud;
            for (int& voisin : voisins[noeud]){
                  voisin = getEns(voisin);
                  if ((vals[noeud] > vals[voisin]) || (vals[noeud] == vals[voisin] && voisin < noeud)){
                        ens[voisin] = noeud;
                        enfants[noeud].pb(voisin);
                  }
            }
            root = noeud;
      }
/*
      for (int noeud = 0; noeud < nNoeuds; ++noeud){
            cout << "Noeud " << noeud << endl;
            for (int enf : enfants[noeud])
                  cout << enf << " ";
            cout << endl;
      }*/

      dfs(root);
      complete(root);
      for(int i = 0; i < nNoeuds; ++i)
            cout << vainqueur[i];
      cout << endl;
      return 0;   
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 21460 KB Output is correct
2 Correct 10 ms 21464 KB Output is correct
3 Correct 10 ms 21580 KB Output is correct
4 Correct 11 ms 21716 KB Output is correct
5 Correct 12 ms 21588 KB Output is correct
6 Correct 12 ms 21636 KB Output is correct
7 Correct 12 ms 21716 KB Output is correct
8 Correct 11 ms 21588 KB Output is correct
9 Correct 11 ms 21844 KB Output is correct
10 Correct 12 ms 21588 KB Output is correct
11 Correct 11 ms 21588 KB Output is correct
12 Correct 14 ms 21572 KB Output is correct
13 Correct 13 ms 21844 KB Output is correct
14 Correct 12 ms 21716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 21396 KB Output is correct
2 Correct 11 ms 21464 KB Output is correct
3 Correct 161 ms 51036 KB Output is correct
4 Correct 156 ms 63268 KB Output is correct
5 Correct 214 ms 43312 KB Output is correct
6 Correct 205 ms 43892 KB Output is correct
7 Correct 225 ms 44060 KB Output is correct
8 Correct 210 ms 65104 KB Output is correct
9 Correct 170 ms 42088 KB Output is correct
10 Correct 122 ms 41056 KB Output is correct
11 Correct 156 ms 65840 KB Output is correct
12 Correct 244 ms 49764 KB Output is correct
13 Correct 170 ms 64048 KB Output is correct
14 Correct 166 ms 62492 KB Output is correct
15 Correct 188 ms 64208 KB Output is correct
16 Correct 143 ms 63728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 21460 KB Output is correct
2 Correct 212 ms 42376 KB Output is correct
3 Correct 206 ms 42500 KB Output is correct
4 Correct 187 ms 64044 KB Output is correct
5 Correct 158 ms 58952 KB Output is correct
6 Correct 199 ms 42612 KB Output is correct
7 Correct 185 ms 64160 KB Output is correct
8 Correct 209 ms 64168 KB Output is correct
9 Correct 119 ms 63796 KB Output is correct
10 Correct 155 ms 50156 KB Output is correct
11 Correct 158 ms 46200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 21460 KB Output is correct
2 Correct 276 ms 44752 KB Output is correct
3 Correct 252 ms 44280 KB Output is correct
4 Correct 252 ms 44276 KB Output is correct
5 Correct 243 ms 45500 KB Output is correct
6 Correct 219 ms 46380 KB Output is correct
7 Correct 143 ms 54472 KB Output is correct
8 Correct 118 ms 65592 KB Output is correct
9 Correct 141 ms 37100 KB Output is correct
10 Correct 228 ms 45404 KB Output is correct
11 Correct 169 ms 46336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 21460 KB Output is correct
2 Correct 10 ms 21464 KB Output is correct
3 Correct 10 ms 21580 KB Output is correct
4 Correct 11 ms 21716 KB Output is correct
5 Correct 12 ms 21588 KB Output is correct
6 Correct 12 ms 21636 KB Output is correct
7 Correct 12 ms 21716 KB Output is correct
8 Correct 11 ms 21588 KB Output is correct
9 Correct 11 ms 21844 KB Output is correct
10 Correct 12 ms 21588 KB Output is correct
11 Correct 11 ms 21588 KB Output is correct
12 Correct 14 ms 21572 KB Output is correct
13 Correct 13 ms 21844 KB Output is correct
14 Correct 12 ms 21716 KB Output is correct
15 Correct 10 ms 21396 KB Output is correct
16 Correct 11 ms 21464 KB Output is correct
17 Correct 161 ms 51036 KB Output is correct
18 Correct 156 ms 63268 KB Output is correct
19 Correct 214 ms 43312 KB Output is correct
20 Correct 205 ms 43892 KB Output is correct
21 Correct 225 ms 44060 KB Output is correct
22 Correct 210 ms 65104 KB Output is correct
23 Correct 170 ms 42088 KB Output is correct
24 Correct 122 ms 41056 KB Output is correct
25 Correct 156 ms 65840 KB Output is correct
26 Correct 244 ms 49764 KB Output is correct
27 Correct 170 ms 64048 KB Output is correct
28 Correct 166 ms 62492 KB Output is correct
29 Correct 188 ms 64208 KB Output is correct
30 Correct 143 ms 63728 KB Output is correct
31 Correct 14 ms 21460 KB Output is correct
32 Correct 212 ms 42376 KB Output is correct
33 Correct 206 ms 42500 KB Output is correct
34 Correct 187 ms 64044 KB Output is correct
35 Correct 158 ms 58952 KB Output is correct
36 Correct 199 ms 42612 KB Output is correct
37 Correct 185 ms 64160 KB Output is correct
38 Correct 209 ms 64168 KB Output is correct
39 Correct 119 ms 63796 KB Output is correct
40 Correct 155 ms 50156 KB Output is correct
41 Correct 158 ms 46200 KB Output is correct
42 Correct 11 ms 21460 KB Output is correct
43 Correct 276 ms 44752 KB Output is correct
44 Correct 252 ms 44280 KB Output is correct
45 Correct 252 ms 44276 KB Output is correct
46 Correct 243 ms 45500 KB Output is correct
47 Correct 219 ms 46380 KB Output is correct
48 Correct 143 ms 54472 KB Output is correct
49 Correct 118 ms 65592 KB Output is correct
50 Correct 141 ms 37100 KB Output is correct
51 Correct 228 ms 45404 KB Output is correct
52 Correct 169 ms 46336 KB Output is correct
53 Correct 13 ms 21476 KB Output is correct
54 Correct 11 ms 21460 KB Output is correct
55 Correct 12 ms 21472 KB Output is correct
56 Correct 15 ms 21664 KB Output is correct
57 Correct 12 ms 21716 KB Output is correct
58 Correct 15 ms 21664 KB Output is correct
59 Correct 12 ms 21620 KB Output is correct
60 Correct 13 ms 21664 KB Output is correct
61 Correct 13 ms 21876 KB Output is correct
62 Correct 13 ms 21616 KB Output is correct
63 Correct 12 ms 21600 KB Output is correct
64 Correct 12 ms 21644 KB Output is correct
65 Correct 11 ms 21844 KB Output is correct
66 Correct 12 ms 21680 KB Output is correct
67 Correct 169 ms 51156 KB Output is correct
68 Correct 185 ms 63288 KB Output is correct
69 Correct 209 ms 43292 KB Output is correct
70 Correct 219 ms 43912 KB Output is correct
71 Correct 202 ms 44188 KB Output is correct
72 Correct 207 ms 65232 KB Output is correct
73 Correct 159 ms 42072 KB Output is correct
74 Correct 130 ms 41188 KB Output is correct
75 Correct 165 ms 65776 KB Output is correct
76 Correct 225 ms 49752 KB Output is correct
77 Correct 181 ms 64112 KB Output is correct
78 Correct 164 ms 62496 KB Output is correct
79 Correct 168 ms 64288 KB Output is correct
80 Correct 120 ms 63724 KB Output is correct
81 Correct 240 ms 42464 KB Output is correct
82 Correct 211 ms 42592 KB Output is correct
83 Correct 186 ms 64168 KB Output is correct
84 Correct 158 ms 58944 KB Output is correct
85 Correct 204 ms 42580 KB Output is correct
86 Correct 176 ms 64192 KB Output is correct
87 Correct 191 ms 64204 KB Output is correct
88 Correct 162 ms 50148 KB Output is correct
89 Correct 165 ms 46228 KB Output is correct
90 Correct 244 ms 44944 KB Output is correct
91 Correct 239 ms 44212 KB Output is correct
92 Correct 263 ms 44324 KB Output is correct
93 Correct 239 ms 45744 KB Output is correct
94 Correct 210 ms 46528 KB Output is correct
95 Correct 171 ms 54576 KB Output is correct
96 Correct 115 ms 65720 KB Output is correct
97 Correct 138 ms 37020 KB Output is correct
98 Correct 265 ms 45328 KB Output is correct
99 Correct 160 ms 46268 KB Output is correct
100 Correct 53 ms 26528 KB Output is correct
101 Correct 305 ms 43940 KB Output is correct
102 Correct 187 ms 45856 KB Output is correct
103 Correct 227 ms 45340 KB Output is correct
104 Correct 293 ms 45208 KB Output is correct