Submission #603977

#TimeUsernameProblemLanguageResultExecution timeMemory
603977Ahmadsm2005Stranded Far From Home (BOI22_island)C++17
10 / 100
1094 ms15784 KiB
#include <bits/stdc++.h> //#define int long long using namespace std; int N,M,V[200001],X,Y,VIS[200001]; int R[200001]; vector<int>edges[200001]; void BFS(int X){ for(int i = 0; i < edges[X].size(); i += 1){ if(R[edges[X][i]] == 0 && V[edges[X][i]] == V[X]){ R[X] = 0; return; } else if(R[edges[X][i]] == 1 && V[edges[X][i]] == V[X]){ R[X] = 1; return; } } for(int i = 0; i < N; i += 1)VIS[i] = 0; priority_queue<pair<int,int>>Q; int CNT = V[X]; Q.push({0,X}); while(Q.size()){ int F = Q.top().second,S = -Q.top().first; Q.pop(); if(VIS[F])continue; VIS[F] = 1; if(S > CNT){ R[X] = 0; return; } CNT += S; CNT = min(CNT,(int)1e9); for(int i = 0; i < edges[F].size(); i += 1){ Q.push({-V[edges[F][i]],edges[F][i]}); } } R[X] = 1; } int32_t main() { cin.tie(0),iostream::sync_with_stdio(0); cin>>N>>M; for(int i = 0; i < N; i += 1){ cin>>V[i]; R[i] = -1; } for(int i = 0; i < M; i += 1){ cin>>X>>Y; edges[X - 1].push_back(Y - 1),edges[Y - 1].push_back(X - 1); } for(int i = 0; i < N; i += 1){ BFS(i); } for(int i = 0; i < N; i += 1)cout<<R[i]; }

Compilation message (stderr)

island.cpp: In function 'void BFS(int)':
island.cpp:8:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for(int i = 0; i < edges[X].size(); i += 1){
      |                    ~~^~~~~~~~~~~~~~~~~
island.cpp:33:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for(int i = 0; i < edges[F].size(); i += 1){
      |                        ~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...