Submission #792200

#TimeUsernameProblemLanguageResultExecution timeMemory
792200cig32Cijanobakterije (COCI21_cijanobakterije)C++17
70 / 70
37 ms17260 KiB
#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 (stderr)

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 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...