Submission #792200

# Submission time Handle Problem Language Result Execution time Memory
792200 2023-07-24T17:27:20 Z cig32 Cijanobakterije (COCI21_cijanobakterije) C++17
70 / 70
37 ms 17260 KB
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
#define int long long
const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
  int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
  if(p==0) return 1 % MOD;
  int r = bm(b, p >> 1);
  if(p&1) return (((r*r) % MOD) * b) % MOD;
  return (r*r) % MOD;
}
int inv(int b) { 
  return bm(b, MOD-2);
}
int fastlog(int x) {
  return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void printcase(int i) { cout << "Case #" << i << ": "; }
vector<int> adj[MAXN];
bool vis[MAXN];
int n, m;
int madep,id;
int dep[MAXN];
vector<int>ff;
void dfs(int node){
  vis[node]=1;
  ff.push_back(node);
  if(dep[node]>madep){
    madep=dep[node];
    id=node;
  }
  for(int x:adj[node]){
    if(!vis[x]){
      dep[x]=dep[node]+1;
      dfs(x);
    }
  }
}
void solve(int tc) {
  cin >> n >> m;
  for(int i=0; i<m; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  int ans = 0;
  for(int i=1; i<=n; i++ ){
    if(!vis[i]) {
      madep=-1;
      ff.clear();
      dfs(i);
      for(int q: ff) vis[q]=dep[q]=0;
      int no=id;
      madep=-1;
      ff.clear();
      dfs(no);
      ans+=madep+1;
      //cout<<i<<" "<<madep+1<<"\n";
    }
  }
  cout<<ans<<"\n";
}
int32_t main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; //cin >> t;
  for(int i=1; i<=t; i++) solve(i);
}
// 勿忘初衷

Compilation message

Main.cpp: In function 'void solve(long long int)':
Main.cpp:58:35: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   58 |       for(int q: ff) vis[q]=dep[q]=0;
      |                             ~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6320 KB Output is correct
2 Correct 12 ms 7504 KB Output is correct
3 Correct 16 ms 8516 KB Output is correct
4 Correct 22 ms 9956 KB Output is correct
5 Correct 27 ms 10940 KB Output is correct
6 Correct 36 ms 11944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 17260 KB Output is correct
2 Correct 6 ms 5560 KB Output is correct
3 Correct 7 ms 6192 KB Output is correct
4 Correct 9 ms 6936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5028 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 5 ms 5972 KB Output is correct
6 Correct 8 ms 6980 KB Output is correct
7 Correct 13 ms 8236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5056 KB Output is correct
3 Correct 3 ms 5028 KB Output is correct
4 Correct 4 ms 4948 KB Output is correct
5 Correct 3 ms 5036 KB Output is correct
6 Correct 4 ms 5028 KB Output is correct
7 Correct 3 ms 5032 KB Output is correct
8 Correct 3 ms 5032 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 3 ms 5032 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6320 KB Output is correct
2 Correct 12 ms 7504 KB Output is correct
3 Correct 16 ms 8516 KB Output is correct
4 Correct 22 ms 9956 KB Output is correct
5 Correct 27 ms 10940 KB Output is correct
6 Correct 36 ms 11944 KB Output is correct
7 Correct 29 ms 17260 KB Output is correct
8 Correct 6 ms 5560 KB Output is correct
9 Correct 7 ms 6192 KB Output is correct
10 Correct 9 ms 6936 KB Output is correct
11 Correct 3 ms 5028 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 5 ms 5972 KB Output is correct
16 Correct 8 ms 6980 KB Output is correct
17 Correct 13 ms 8236 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 3 ms 5056 KB Output is correct
20 Correct 3 ms 5028 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 3 ms 5036 KB Output is correct
23 Correct 4 ms 5028 KB Output is correct
24 Correct 3 ms 5032 KB Output is correct
25 Correct 3 ms 5032 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5032 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 37 ms 11852 KB Output is correct
30 Correct 9 ms 6868 KB Output is correct
31 Correct 26 ms 9792 KB Output is correct
32 Correct 13 ms 7872 KB Output is correct
33 Correct 33 ms 10452 KB Output is correct
34 Correct 18 ms 8596 KB Output is correct
35 Correct 28 ms 10024 KB Output is correct
36 Correct 24 ms 9920 KB Output is correct
37 Correct 29 ms 10432 KB Output is correct
38 Correct 31 ms 11060 KB Output is correct
39 Correct 22 ms 10068 KB Output is correct