제출 #824045

#제출 시각아이디문제언어결과실행 시간메모리
824045AmylopectinStranded Far From Home (BOI22_island)C++14
100 / 100
199 ms79072 KiB
#include <stdio.h> #include <iostream> #include <vector> #include <queue> #include <algorithm> using namespace std; const long long mxn = 1e6 + 10; struct we { long long idx,val; }; bool cmp(const struct we &l,const struct we &r) { return l.val < r.val; } struct we sot[mxn] = {}; char ans[mxn] = {}; long long npop[mxn] = {},gr[mxn] = {},he[mxn] = {},siz[mxn] = {},u[mxn] = {}; vector<long long> pat[mxn] = {},tre[mxn] = {}; long long figr(long long l) { long long cl = l,f; while(l != gr[l]) { l = gr[l]; } while(cl != gr[cl]) { f = gr[cl]; gr[cl] = l; cl = f; } return l; } long long mer(long long cl,long long cr) { long long l = figr(cl),r = figr(cr); gr[r] = l; siz[l] += siz[r]; return l; } long long re(long long cn) { long long i,j,fn; ans[cn] = '1'; for(i=0; i<tre[cn].size(); i++) { fn = tre[cn][i]; re(fn); } return 0; } int main() { long long i,j,n,m,cn,cm,fn,fm; scanf("%lld %lld",&n,&m); for(i=0; i<n; i++) { scanf("%lld",&npop[i]); sot[i] = {i,npop[i]}; he[i] = i; gr[i] = i; siz[i] = npop[i]; ans[i] = '0'; } for(i=0; i<m; i++) { scanf("%lld %lld",&cn,&cm); pat[cn-1].push_back(cm-1); pat[cm-1].push_back(cn-1); } sort(sot,sot+n,cmp); for(i=0; i<n; i++) { cn = sot[i].idx; u[cn] = 1; for(j=0; j<pat[cn].size(); j++) { fn = pat[cn][j]; if(u[fn] == 0) { continue; } cm = figr(cn); fm = figr(fn); if(cm != fm) { if(siz[fm] >= npop[cn]) { tre[cn].push_back(he[fm]); } mer(cm,fm); } } } re(sot[n-1].idx); printf("%s\n",ans); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

island.cpp: In function 'long long int re(long long int)':
island.cpp:46:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(i=0; i<tre[cn].size(); i++)
      |              ~^~~~~~~~~~~~~~~
island.cpp:44:17: warning: unused variable 'j' [-Wunused-variable]
   44 |     long long i,j,fn;
      |                 ^
island.cpp: In function 'int main()':
island.cpp:77:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         for(j=0; j<pat[cn].size(); j++)
      |                  ~^~~~~~~~~~~~~~~
island.cpp:56:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |     scanf("%lld %lld",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
island.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         scanf("%lld",&npop[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~
island.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         scanf("%lld %lld",&cn,&cm);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
#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...