# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
335386 |
2020-12-12T09:49:53 Z |
blue |
Power Plant (JOI20_power) |
C++11 |
|
6 ms |
8184 KB |
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int N;
vector<int> edge[200001];
vector<int> plant(200000);
vector<int> edge_count(200001, 0);
vector<int> stream_count(200001, 0);
vector<int> visit(200001, 0);
int res = 0;
int main()
{
cin >> N;
int a, b;
for(int i = 1; i <= N-1; i++)
{
cin >> a >> b;
edge[a].push_back(b);
edge_count[a]++;
edge[b].push_back(a);
edge_count[b]++;
}
char c;
for(int i = 1; i <= N; i++)
{
cin >> c;
plant[i] = (c == '1');
}
queue<int> tbv;
for(int i = 1; i <= N; i++) if(edge_count[i] == 1)
{
tbv.push(i);
}
while(!tbv.empty())
{
a = tbv.front();
tbv.pop();
if(visit[a]) continue;
visit[a] = 1;
for(int v: edge[a])
{
if(!visit[v])
{
edge_count[v]--;
if(edge_count[v] <= 1)
{
tbv.push(v);
}
}
else
{
stream_count[a] += stream_count[v];
}
}
if(stream_count[a] > 1 && plant[a]) res--;
if(stream_count[a] == 0 && plant[a])
{
stream_count[a]++;
res++;
}
}
cout << res << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
8184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
8184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
8184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |