# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
883718 | HossamHero7 | Papričice (COCI20_papricice) | C++14 | 1070 ms | 5212 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const int N = 2e5 + 5;
int n;
vector<pair<int,int>> adj[N];
vector<bool> can;
vector<bool> vis;
int cnt = 0;
void dfs(int node){
vis[node] = 1;
cnt ++;
for(auto [e,ch] : adj[node]){
if(can[e] && !vis[ch]) dfs(ch);
}
}
int ans = 1e9;
void calc(){
for(int i=1;i<=n;i++) vis[i] = 0;
vector<int> comps;
for(int i=1;i<=n;i++){
if(vis[i]) continue;
cnt = 0;
dfs(i);
comps.push_back(cnt);
}
sort(comps.begin(),comps.end());
ans = min(ans , comps.back() - comps[0]);
}
void solve(){
cin>>n;
for(int i=0;i<n-1;i++){
int a,b;
cin>>a>>b;
adj[a].push_back({i,b});
adj[b].push_back({i,a});
}
can.resize(n-1,1);
vis.resize(n+1);
for(int i=0;i<n-1;i++){
can[i] = 0;
for(int j=i+1;j<n-1;j++){
can[j] = 0;
calc();
can[j] = 1;
}
can[i] = 1;
}
cout<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |