제출 #680304

#제출 시각아이디문제언어결과실행 시간메모리
680304KG07Cijanobakterije (COCI21_cijanobakterije)C++14
0 / 70
63 ms9048 KiB
// Online C++ compiler to run C++ program online #include <bits/stdc++.h> using namespace std; vector<int> h[100000]; int a[100000]; bool b[100000]; int c[100000]; pair<int, int> d[100000]; int find(int x){ if(x == a[x])return x; else return a[x] = find(a[x]); } queue<pair<int, int>> q; int main() { // Write C++ code here int n, m; cin >> n >> m; for(int i = 0; i < n; i++)a[i] = i; for(int i = 0; i < m; i++){ int u, v; cin >> u >> v; h[u].push_back(v); h[v].push_back(u); a[find(u)] = find(v); b[find(u)] = true; } for(int i = 1; i <= n; i++){ if(!b[i]){ d[i] = {i, i}; for(int j = 0; j < h[i].size(); j++)q.push({h[i][j], i}); } while(!q.empty()){ int u = q.front().first; int v = q.front().second; q.pop(); c[u] = c[v] + 1; if(c[u] > c[d[find(u)].first]){d[find(u)].second = d[find(u)].first; d[find(u)].first = u;} else if(c[u] > c[d[find(u)].second])d[find(u)].second = u; for(int j = 0; j < h[u].size(); j++)if(h[u][j] != v)q.push({h[u][j], u}); } } int s = 0; for(int i = 1; i <= n; i++){ //cout << i << " " << a[i] << " " << b[i] << " " << c[i] << " " << c[d[i].first] + c[d[i].second] << "\n"; if(!b[i])s += c[d[i].first] + c[d[i].second]; } cout << s; return 0; }

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

Main.cpp: In function 'int main()':
Main.cpp:31:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |             for(int j = 0; j < h[i].size(); j++)q.push({h[i][j], i});
      |                            ~~^~~~~~~~~~~~~
Main.cpp:40:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |             for(int j = 0; j < h[u].size(); j++)if(h[u][j] != v)q.push({h[u][j], u});
      |                            ~~^~~~~~~~~~~~~
#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...