제출 #155952

#제출 시각아이디문제언어결과실행 시간메모리
155952nishkarshBosses (BOI16_bosses)C++14
100 / 100
852 ms24060 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define F first #define S second #define pii pair<int,int> #define pll pair<ll,ll> #define pcc pair<char,char> #define vi vector <int> #define vl vector <ll> #define sd(x) scanf("%d",&x) #define slld(x) scanf("%lld",&x) #define pd(x) printf("%d",x) #define plld(x) printf("%lld",x) #define pds(x) printf("%d ",x) #define pllds(x) printf("%lld ",x) #define pdn(x) printf("%d\n",x) #define plldn(x) printf("%lld\n",x) #define INF 2e9 #define INFLL 4e18 using namespace std; ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9 ll ans=1; while(exponent){ if(exponent&1)ans=(ans*base)%mod; base=(base*base)%mod; exponent/=2; } return ans; } ll gcd(ll a, ll b){ if(b==0) return a; else return gcd(b,a%b); } const int upperlimit = 1e6+1; const int mod = 1e9+7; vi adj[upperlimit]; bool visited[upperlimit]; queue <pii> to_visit; ll temp=0; void bfs(){ while(! to_visit.empty()){ pii x=to_visit.front(); int node=x.F; if(visited[node]){ to_visit.pop(); continue; } visited[node]=true; temp+=x.S; for(int i = 0; i < adj[node].size(); i++) if(! visited[adj[node][i]]) to_visit.push(mp(adj[node][i],(x.S)+1)); to_visit.pop(); } } int main() { int n,k,node; sd(n); for(int i = 1; i <= n; i++){ sd(k); for(int j = 1; j <= k; j++){ sd(node); adj[node].pb(i); } } ll ans=INFLL; for(int i = 1; i <= n; i++){ to_visit.push(mp(i,1)); bfs(); bool check=true; for(int j = 1; j <= n; j++){ check&=visited[j]; visited[j]=false; } if(check) ans=min(ans,temp); temp=0; } plld(ans); return 0; }

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

bosses.cpp: In function 'void bfs()':
bosses.cpp:52:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < adj[node].size(); i++) if(! visited[adj[node][i]]) to_visit.push(mp(adj[node][i],(x.S)+1));
                  ~~^~~~~~~~~~~~~~~~~~
bosses.cpp: In function 'int main()':
bosses.cpp:12:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define sd(x) scanf("%d",&x)
               ~~~~~^~~~~~~~~
bosses.cpp:58:2: note: in expansion of macro 'sd'
  sd(n);
  ^~
bosses.cpp:12:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define sd(x) scanf("%d",&x)
               ~~~~~^~~~~~~~~
bosses.cpp:60:3: note: in expansion of macro 'sd'
   sd(k);
   ^~
bosses.cpp:12:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define sd(x) scanf("%d",&x)
               ~~~~~^~~~~~~~~
bosses.cpp:62:4: note: in expansion of macro 'sd'
    sd(node);
    ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...