답안 #604179

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
604179 2022-07-24T19:53:51 Z DanerZein Stranded Far From Home (BOI22_island) C++14
20 / 100
1000 ms 256060 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
const int MAX_N=2e5+10;
vector<vi> G;
int ha[MAX_N];
bool vis[MAX_N];
int n,m;
void bfs(int u){
  for(int i=0;i<n;i++) vis[i]=0;
  priority_queue<ii, vector<ii>, greater<ii> > q;
  vis[u]=1; 
  ll co=ha[u];
  for(auto &v:G[u]){
    q.push(ii(ha[v],v));
  }
  while(!q.empty()){
    int x=q.top().second; q.pop();
    if(co<ha[x]) continue;
    vis[x]=1;
    co+=ha[x];
    for(auto &v:G[x]){
      if(!vis[v]){
        q.push(ii(ha[v],v));
      }
    }
  }
}
int pa[MAX_N];
ll sb[MAX_N];
void dfs(int u,int p){
  pa[u]=p;
  sb[u]=ha[u];
  for(auto &v:G[u]){
    if(v!=p){
      dfs(v,u);
      sb[u]+=sb[v];
    }
  }
}
int main(){
  cin>>n>>m;
  G.resize(n+1);
  for(int i=0;i<n;i++) cin>>ha[i];
  for(int i=0;i<m;i++){
    int a,b; cin>>a>>b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  string ans="";
  if(n>2000){
    ans="1";
    dfs(0,0);
    for(int i=1;i<n;i++){
      if(sb[i]>=ha[pa[i]] && ans[pa[i]]=='1') ans+='1';
      else ans+='0';
    }
  }
  else{
    for(int i=0;i<n;i++){
      bfs(i);
      bool all=1;
      for(int j=0;j<n;j++) all&=vis[j];
      if(all) ans+='1';
      else ans+='0';
    }
  }
  cout<<ans<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 208 ms 340 KB Output is correct
5 Correct 159 ms 432 KB Output is correct
6 Correct 293 ms 432 KB Output is correct
7 Correct 211 ms 340 KB Output is correct
8 Correct 170 ms 340 KB Output is correct
9 Correct 235 ms 460 KB Output is correct
10 Correct 65 ms 340 KB Output is correct
11 Correct 64 ms 460 KB Output is correct
12 Correct 66 ms 448 KB Output is correct
13 Correct 110 ms 444 KB Output is correct
14 Correct 92 ms 440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 241 ms 19864 KB Output is correct
4 Correct 218 ms 19804 KB Output is correct
5 Correct 239 ms 14444 KB Output is correct
6 Correct 269 ms 14904 KB Output is correct
7 Correct 243 ms 14988 KB Output is correct
8 Correct 251 ms 14980 KB Output is correct
9 Correct 278 ms 14844 KB Output is correct
10 Correct 183 ms 15776 KB Output is correct
11 Correct 188 ms 15740 KB Output is correct
12 Correct 232 ms 15016 KB Output is correct
13 Correct 203 ms 27428 KB Output is correct
14 Correct 213 ms 27404 KB Output is correct
15 Correct 248 ms 27372 KB Output is correct
16 Correct 192 ms 27136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 243 ms 27232 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1091 ms 256060 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 208 ms 340 KB Output is correct
5 Correct 159 ms 432 KB Output is correct
6 Correct 293 ms 432 KB Output is correct
7 Correct 211 ms 340 KB Output is correct
8 Correct 170 ms 340 KB Output is correct
9 Correct 235 ms 460 KB Output is correct
10 Correct 65 ms 340 KB Output is correct
11 Correct 64 ms 460 KB Output is correct
12 Correct 66 ms 448 KB Output is correct
13 Correct 110 ms 444 KB Output is correct
14 Correct 92 ms 440 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 241 ms 19864 KB Output is correct
18 Correct 218 ms 19804 KB Output is correct
19 Correct 239 ms 14444 KB Output is correct
20 Correct 269 ms 14904 KB Output is correct
21 Correct 243 ms 14988 KB Output is correct
22 Correct 251 ms 14980 KB Output is correct
23 Correct 278 ms 14844 KB Output is correct
24 Correct 183 ms 15776 KB Output is correct
25 Correct 188 ms 15740 KB Output is correct
26 Correct 232 ms 15016 KB Output is correct
27 Correct 203 ms 27428 KB Output is correct
28 Correct 213 ms 27404 KB Output is correct
29 Correct 248 ms 27372 KB Output is correct
30 Correct 192 ms 27136 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 243 ms 27232 KB Output isn't correct
33 Halted 0 ms 0 KB -