Submission #948903

# Submission time Handle Problem Language Result Execution time Memory
948903 2024-03-18T16:06:53 Z vin Cijanobakterije (COCI21_cijanobakterije) C++14
15 / 70
20 ms 604 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>

const int INF = 2147483645;
const int maxN = (int)1e3+5;
const ll LLINF = LLONG_MAX;
//const ll mod = 998244353;
const ll mod = 1000000007;

vector<int> adj[maxN];
int dist[maxN], ctr=1, cc[maxN];
bool vis[maxN], avis[maxN];

void dfs(int s) {
	vis[s] = true;
	avis[s] = true;
	if (!cc[s]) cc[s] = ctr;
	for (auto i: adj[s]) {
		if (vis[i]) continue;
		vis[i] = true;
		avis[i] = true;
		dist[i] = dist[s]+1;
		dfs(i);
	}
}

void solv() {
	int n, m, a, b;
    cin>>n>>m;
    for (int i=0;i<m;i++) {
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    int mx = 0, start = 1, ans = 0, res = 0;
    for (int i=1;i<=n;i++) {
    	mx = 0;
    	ans = 0;
    	start = i;
    	memset(dist, 0, sizeof dist);
    	memset(vis, 0, sizeof vis);
    	dfs(i);
    	for (int j=1;j<=n;j++) {
    		if (dist[j] > mx) {
	            mx = dist[j];
	            start = j;
        	}
		}
    	memset(dist, 0, sizeof dist);
    	memset(vis, 0, sizeof vis);
		dfs(start);
	    for (int j=1;j<=n;j++) {
	        ans = max(ans, dist[j]);
	    }
	    if (cc[i] == ctr) res += ans+1;
	    ctr++;
    }
    cout<<res<<'\n';
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t=1;
//    cin>>t;
    while (t--) solv();
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Runtime error 1 ms 604 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 5 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 13 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -