답안 #660600

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
660600 2022-11-22T14:29:39 Z sandry24 Power Plant (JOI20_power) C++17
0 / 100
4 ms 4948 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second

vector<vi> adj(200005);
vector<bool> visited(200005);
string hasGen;
int temp = 0;
bool many = false;

void dfs(int x, int p){
    visited[x] = 1;
    int branch = 0;
    for(auto i : adj[x]){
        int temp2 = temp;
        if(hasGen[i-1] == '1' && i != p)
            temp++;
        if(!visited[i] && hasGen[i-1] != '1'){
            dfs(i, x);
        }
        if(temp2 != temp)
            branch++;
    }
    if(branch >= 2)
        many = true;
    else
        many = false;
}
 
void solve(){
    int n;
    cin >> n;
    for(int i = 0; i < n-1; i++){
        int a, b;
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    cin >> hasGen;
    int ans = 1;
    for(int i = 1; i <= n; i++){
        temp = 0; many = false;
        if(!visited[i]){
            //cout << i << ' ';
            dfs(i, -1);
            if(hasGen[i-1] == '1')
                temp++;
            //cout << temp << '\n'; 
        }
        if(many)
            temp -= 2;
        ans = max(ans, temp);
    }
    cout << ans << '\n';
}
 
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Incorrect 3 ms 4948 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Incorrect 3 ms 4948 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Incorrect 3 ms 4948 KB Output isn't correct
4 Halted 0 ms 0 KB -