# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
870870 |
2023-11-09T11:17:22 Z |
Rafi22 |
Svjetlo (COCI20_svjetlo) |
C++14 |
|
13 ms |
2308 KB |
#include <bits/stdc++.h>
#define ll long long
#define ld double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
int inf=1000000007;
int mod=1000000007;
int mod1=998244353;
const int N=107;
vector<int>G[N];
bool is[N],t[N],x[N];
bool nie[N];
void dfs(int v,int o,int k)
{
t[v]=!is[v];
x[v]=is[v];
nie[v]=(v==k);
for(auto u:G[v])
{
if(u==o) continue;
dfs(u,v,k);
t[v]|=t[u];
nie[v]|=nie[u];
}
}
int cnt;
void dfs1(int v,int o)
{
x[v]^=1;
cnt++;
int ile=0;
for(auto u:G[v])
{
if(u==o||!t[u]) continue;
dfs1(u,v);
if(!nie[u]) ile++;
}
cnt+=ile;
x[v]^=(ile%2);
if(x[v]==0)
{
if(o==0) cnt=inf;
else
{
cnt+=2;
x[v]^=1;
x[o]^=1;
}
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,a,b;
string s;
cin>>n>>s;
for(int i=0;i<n;i++) is[i+1]=s[i]-'0';
for(int i=1;i<n;i++)
{
cin>>a>>b;
G[a].pb(b);
G[b].pb(a);
}
int ans=inf;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
dfs(i,0,j);
cnt=0;
dfs1(i,0);
ans=min(ans,cnt);
}
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
348 KB |
Output is correct |
2 |
Correct |
10 ms |
348 KB |
Output is correct |
3 |
Correct |
9 ms |
468 KB |
Output is correct |
4 |
Correct |
13 ms |
344 KB |
Output is correct |
5 |
Correct |
10 ms |
460 KB |
Output is correct |
6 |
Correct |
9 ms |
344 KB |
Output is correct |
7 |
Correct |
12 ms |
460 KB |
Output is correct |
8 |
Correct |
8 ms |
348 KB |
Output is correct |
9 |
Correct |
8 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
1776 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
2308 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
348 KB |
Output is correct |
2 |
Correct |
10 ms |
348 KB |
Output is correct |
3 |
Correct |
9 ms |
468 KB |
Output is correct |
4 |
Correct |
13 ms |
344 KB |
Output is correct |
5 |
Correct |
10 ms |
460 KB |
Output is correct |
6 |
Correct |
9 ms |
344 KB |
Output is correct |
7 |
Correct |
12 ms |
460 KB |
Output is correct |
8 |
Correct |
8 ms |
348 KB |
Output is correct |
9 |
Correct |
8 ms |
464 KB |
Output is correct |
10 |
Runtime error |
2 ms |
1776 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |