#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define rip(i,a,b) for(ll i=a;i<=b;i++)
#define in insert
using namespace std;
const ll M=998244353;
vector<int> adj[205];
bool vis[205];
vector< pair< int , int> > v;
int ans=INT_MAX;
int cnt=0;
set< pair< int ,int > > s;
void dfs(int node){
vis[node]=1;
cnt++;
for(auto u : adj[node]){
if (vis[u]) continue;
if (s.find({node,u})!=s.end() || s.find({u,node})!=s.end()) continue;
dfs(u);
}
return ;
}
int32_t main(){
//ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n;
cin>>n;
for(int i=1;i<=n-1;i++){
int x,y;
cin>>x>>y;
adj[x].pb(y);
adj[y].pb(x);
v.pb({x,y});
}
for(int i=0;i<v.size();i++){
for(int j=0;j<v.size();j++){
if(i!=j){
int mx=-1,mi=INT_MAX;
s.in(v[i]);
s.in(v[j]);
for(int i=1;i<=n;i++) vis[i]=0;
for(int i=1;i<=n;i++){
cnt=0;
if(vis[i]) continue;
dfs(i);
mi=min(mi,cnt);
mx=max(mx,cnt);
}
s.clear();
ans=min(ans,mx-mi);
}
}
}
cout<<ans;
return 0;
}
Compilation message
papricice.cpp: In function 'int32_t main()':
papricice.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
papricice.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int j=0;j<v.size();j++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
183 ms |
300 KB |
Output is correct |
2 |
Correct |
180 ms |
296 KB |
Output is correct |
3 |
Correct |
148 ms |
332 KB |
Output is correct |
4 |
Correct |
166 ms |
292 KB |
Output is correct |
5 |
Correct |
169 ms |
292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
183 ms |
300 KB |
Output is correct |
2 |
Correct |
180 ms |
296 KB |
Output is correct |
3 |
Correct |
148 ms |
332 KB |
Output is correct |
4 |
Correct |
166 ms |
292 KB |
Output is correct |
5 |
Correct |
169 ms |
292 KB |
Output is correct |
6 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
183 ms |
300 KB |
Output is correct |
2 |
Correct |
180 ms |
296 KB |
Output is correct |
3 |
Correct |
148 ms |
332 KB |
Output is correct |
4 |
Correct |
166 ms |
292 KB |
Output is correct |
5 |
Correct |
169 ms |
292 KB |
Output is correct |
6 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |