Submission #1033074

# Submission time Handle Problem Language Result Execution time Memory
1033074 2024-07-24T12:34:54 Z NoLove Cijanobakterije (COCI21_cijanobakterije) C++14
21 / 70
36 ms 13404 KB
/**
 *    author : Lăng Trọng Đạt
 *    created: 24-07-2024 
**/
#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define int long long
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
using pii = pair<int, int>;
using vi = vector<int>;
#define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
void mx(int& a, int b) { if (b > a) a = b; }
void mi(int& a, int b) { if (b < a) a = b; }
#define si(x) (int)(x.size())
const int INF = 1e18;
const int MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;
vector<int> adj[MAXN];
int g[MAXN];
bool vis[MAXN];
int n, m, a, b;

int root = 0;
int d[MAXN];
void dfs(int v, int prv) {
    vis[v] = 1;
    for (int u : adj[v]) {
        if (u == prv) continue;
        d[u] = d[v] + 1;
        dfs(u, v);
    }
    db(v, d[v], root, d[root])
    if (d[v] > d[root]) root = v;
}

int32_t main() {
    cin.tie(0)->sync_with_stdio(0);
    if (fopen("hi.inp", "r")) {
        freopen("hi.inp", "r", stdin);
//        freopen("hi.out", "w", stdout);
    } 

    cin >> n >> m;
    FOR(i, 1, m) {
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }    
    int ans = 0;
    FOR(i, 1, n) {
        if (!vis[i]) {
            if (si(adj[i]) == 0) ans++;
            else {
                dfs(i, -1);
                int tmp = root;
                d[root] = 1;
                db(root)
                dfs(root, -1);
                db(root, d[root], d[1])
                ans += d[root];
            }
        }
    }

    cout << ans;
}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:18:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   18 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
Main.cpp:52:5: note: in expansion of macro 'FOR'
   52 |     FOR(i, 1, m) {
      |     ^~~
Main.cpp:18:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   18 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
Main.cpp:58:5: note: in expansion of macro 'FOR'
   58 |     FOR(i, 1, n) {
      |     ^~~
Main.cpp:63:21: warning: unused variable 'tmp' [-Wunused-variable]
   63 |                 int tmp = root;
      |                     ^~~
Main.cpp:47:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         freopen("hi.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5212 KB Output is correct
2 Correct 11 ms 5976 KB Output is correct
3 Correct 13 ms 6744 KB Output is correct
4 Correct 21 ms 6608 KB Output is correct
5 Correct 24 ms 8400 KB Output is correct
6 Correct 36 ms 9240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 13404 KB Output is correct
2 Incorrect 3 ms 4700 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 1 ms 4188 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 4 ms 5032 KB Output is correct
6 Correct 7 ms 4440 KB Output is correct
7 Correct 11 ms 6484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2820 KB Output is correct
2 Incorrect 1 ms 4292 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5212 KB Output is correct
2 Correct 11 ms 5976 KB Output is correct
3 Correct 13 ms 6744 KB Output is correct
4 Correct 21 ms 6608 KB Output is correct
5 Correct 24 ms 8400 KB Output is correct
6 Correct 36 ms 9240 KB Output is correct
7 Correct 32 ms 13404 KB Output is correct
8 Incorrect 3 ms 4700 KB Output isn't correct
9 Halted 0 ms 0 KB -