# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
680322 | 2023-01-10T14:58:55 Z | KG07 | Cijanobakterije (COCI21_cijanobakterije) | C++14 | 93 ms | 14804 KB |
// 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 = 1; 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); b[find(u)] = true; a[find(u)] = find(v); } for(int i = 1; i <= n; i++){ if(b[i])continue; 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[i].first])d[i].first = u; for(int j = 0; j < h[u].size(); j++)if(h[u][j] != v)q.push({h[u][j], u}); } c[d[i].first] = 0; d[i].second = d[i].first; for(int j = 0; j < h[d[i].first].size(); j++)q.push({h[d[i].first][j], d[i].first}); 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[i].second])d[i].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].second] + 1; } cout << s; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 3356 KB | Output is correct |
2 | Correct | 26 ms | 4368 KB | Output is correct |
3 | Correct | 39 ms | 5228 KB | Output is correct |
4 | Correct | 57 ms | 6192 KB | Output is correct |
5 | Correct | 78 ms | 7116 KB | Output is correct |
6 | Runtime error | 93 ms | 14804 KB | Execution killed with signal 11 |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 77 ms | 6604 KB | Output is correct |
2 | Correct | 7 ms | 3412 KB | Output is correct |
3 | Correct | 14 ms | 4072 KB | Output is correct |
4 | Correct | 18 ms | 4940 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Correct | 1 ms | 2644 KB | Output is correct |
3 | Correct | 2 ms | 2656 KB | Output is correct |
4 | Correct | 1 ms | 2644 KB | Output is correct |
5 | Correct | 9 ms | 3668 KB | Output is correct |
6 | Correct | 17 ms | 4632 KB | Output is correct |
7 | Correct | 23 ms | 5624 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Correct | 2 ms | 2644 KB | Output is correct |
3 | Correct | 2 ms | 2656 KB | Output is correct |
4 | Correct | 2 ms | 2644 KB | Output is correct |
5 | Correct | 2 ms | 2644 KB | Output is correct |
6 | Correct | 2 ms | 2644 KB | Output is correct |
7 | Correct | 2 ms | 2644 KB | Output is correct |
8 | Correct | 2 ms | 2644 KB | Output is correct |
9 | Correct | 2 ms | 2656 KB | Output is correct |
10 | Correct | 2 ms | 2644 KB | Output is correct |
11 | Correct | 2 ms | 2644 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 3356 KB | Output is correct |
2 | Correct | 26 ms | 4368 KB | Output is correct |
3 | Correct | 39 ms | 5228 KB | Output is correct |
4 | Correct | 57 ms | 6192 KB | Output is correct |
5 | Correct | 78 ms | 7116 KB | Output is correct |
6 | Runtime error | 93 ms | 14804 KB | Execution killed with signal 11 |
7 | Halted | 0 ms | 0 KB | - |