제출 #742228

#제출 시각아이디문제언어결과실행 시간메모리
742228angelsFriend (IOI14_friend)C++14
8 / 100
2 ms2676 KiB
/****************************************************************************** Online C++ Compiler. Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <bits/stdc++.h> using namespace std; vector<int> a[100000]; bool visited[100000]; void connect(int x, int y) { a[x].push_back(y); a[y].push_back(x); } int dfs(int x, int val, int n, int confidence[]) { int rez=0, i=0; if(x==n) return val; for(i=a[x].size(); i--;) { if(visited[a[x][i]]==true) break; } if(i<0) { visited[x]=1; rez=dfs(x+1, val+confidence[x], n, confidence); } visited[x]=false; int v=dfs(x+1, val, n, confidence); if(v>rez) rez=v; return v; } int subtask1(int n, int confidence[], int host[], int protocol[]) { for(int i=1; i<n; i++) { if(protocol[i]==0) { connect(host[i], i); } if(protocol[i]==1) { for(int j=a[host[i]].size(); j--;) { connect(a[host[i]][j], i); } } if(protocol[i]==2) { connect(host[i], i); for(int j=a[host[i]].size(); j>0; j--) { connect(a[host[i]][j], i); } } } return dfs(0, 0, n, confidence); } int findSample(int n,int confidence[],int host[],int protocol[]) { int i, w; //cin>>n; //int confidence[n], host[n], protocol[n]; if(n<=10) { w=subtask1(n, confidence, host, protocol); return(w); } for(i=2; i<n; i++) { if(protocol[i-1]!=protocol[i]) break; } if(i>=n) { if(protocol[1]==1) { w=0; for(int j=0; j<n; j++) { w+=confidence[i]; } return w; } else if(protocol[1]==2) { w=-1; for(i=0; i<n; i++) { if(confidence[i]>w) w=confidence[i]; } return w; } } return w; //cout<<w; }

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

friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:105:12: warning: 'w' may be used uninitialized in this function [-Wmaybe-uninitialized]
  105 |     return w;
      |            ^
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...