Submission #497198

#TimeUsernameProblemLanguageResultExecution timeMemory
497198CyberCowShymbulak (IZhO14_shymbulak)C++17
0 / 100
1561 ms8756 KiB
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <string> #include <cmath> #include <map> #include <unordered_map> #include <unordered_set> #include <fstream> #include <iomanip> #include <iterator> #include <stack> #include <deque> using namespace std; using ll = long long; vector<int> v[200004]; queue<int> q; int color[200004], ans = 0, n, ma, c[200004]; void solve() { int i, j, x, y, oo = 1000000000; cin >> n; for ( i = 0; i < n; i++) { cin >> x >> y; v[x].push_back(y); v[y].push_back(x); } color[1] = 1; q.push(1); while (!q.empty()) { x = q.front(); q.pop(); for ( i = 0; i < v[x].size(); i++) { if (!color[v[x][i]]) { color[v[x][i]] = color[x] + 1; q.push(v[x][i]); } } } int ind = 0; for ( i = 1; i <= n; i++) { if (color[i] > ma) { ma = color[i]; ind = i; } color[i] = 0; } color[ind] = 1; q.push(ind); while (!q.empty()) { x = q.front(); q.pop(); for (i = 0; i < v[x].size(); i++) { if (!color[v[x][i]]) { color[v[x][i]] = color[x] + 1; q.push(v[x][i]); } } } ma = 0; for (i = 1; i <= n; i++) { ma = max(ma, color[i]); color[i] = 0; } for ( j = 1; j <= n; j++) { c[j] = 1; color[j] = 1; q.push(j); while (!q.empty()) { x = q.front(); q.pop(); for (i = 0; i < v[x].size(); i++) { if (c[v[x][i]] == 0 || c[v[x][i]] == c[x] + 1) { color[v[x][i]] += color[x]; } if (!c[v[x][i]]) { c[v[x][i]] = c[x] + 1; q.push(v[x][i]); } } } for ( i = 1; i <= n; i++) { if (c[i] == ma) { ans += color[i]; } c[i] = 0; color[i] = 0; } } cout << ans/2; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int tt = 1; //cin >> tt; while (tt--) { solve(); } return 0; }

Compilation message (stderr)

shymbulak.cpp: In function 'void solve()':
shymbulak.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |   for ( i = 0; i < v[x].size(); i++)
      |                ~~^~~~~~~~~~~~~
shymbulak.cpp:63:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   for (i = 0; i < v[x].size(); i++)
      |               ~~^~~~~~~~~~~~~
shymbulak.cpp:87:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |    for (i = 0; i < v[x].size(); i++)
      |                ~~^~~~~~~~~~~~~
shymbulak.cpp:24:18: warning: unused variable 'oo' [-Wunused-variable]
   24 |  int i, j, x, y, oo = 1000000000;
      |                  ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...