답안 #292882

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
292882 2020-09-07T14:35:59 Z limabeans Power Plant (JOI20_power) C++17
6 / 100
1500 ms 23936 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n;
vector<int> g[maxn];
string s;
set<int> broken;
int x,y;
bool dfs(int at, int p) {
    if (at==y) return true;
    for (int to: g[at]) {
	if (to==p) continue;
	if (dfs(to,at)) {
	    if (s[at]=='1' && at!=x) {
		broken.insert(at);
	    }
	    return true;
	}
    }
    return false;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

    cin>>n;
    for (int i=0; i<n-1; i++) {
	int u,v; cin>>u>>v;
	--u; --v;
	g[u].push_back(v);
	g[v].push_back(u);
    }
    
    cin>>s;

    int best = 0;
    for (int mask=0; mask<1<<n; mask++) {
	vector<int> v;
	bool ok = true;
	for (int j=0; j<n && ok; j++) {
	    if (mask>>j&1) {
		if (s[j]=='0') ok=false;
		v.push_back(j);
	    }
	}
	if (!ok) continue;
	broken.clear();
	for (int i=0; i<int(v.size()); i++) {
	    for (int j=i+1; j<int(v.size()); j++) {
		x=v[i]; y=v[j];
		dfs(v[i],-1);
	    }
	}
	int res = 0;
	for (int x: v) {
	    if (!broken.count(x)) res++;
	}
	res -= int(broken.size());
	best = max(best, res);
    }

    cout<<best<<endl;    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 21 ms 23808 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 23 ms 23808 KB Output is correct
5 Correct 29 ms 23808 KB Output is correct
6 Correct 24 ms 23808 KB Output is correct
7 Correct 290 ms 23928 KB Output is correct
8 Correct 405 ms 23808 KB Output is correct
9 Correct 130 ms 23868 KB Output is correct
10 Correct 31 ms 23808 KB Output is correct
11 Correct 322 ms 23928 KB Output is correct
12 Correct 36 ms 23936 KB Output is correct
13 Correct 27 ms 23808 KB Output is correct
14 Correct 38 ms 23808 KB Output is correct
15 Correct 19 ms 23808 KB Output is correct
16 Correct 21 ms 23808 KB Output is correct
17 Correct 150 ms 23868 KB Output is correct
18 Correct 85 ms 23808 KB Output is correct
19 Correct 20 ms 23808 KB Output is correct
20 Correct 25 ms 23808 KB Output is correct
21 Correct 230 ms 23928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 21 ms 23808 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 23 ms 23808 KB Output is correct
5 Correct 29 ms 23808 KB Output is correct
6 Correct 24 ms 23808 KB Output is correct
7 Correct 290 ms 23928 KB Output is correct
8 Correct 405 ms 23808 KB Output is correct
9 Correct 130 ms 23868 KB Output is correct
10 Correct 31 ms 23808 KB Output is correct
11 Correct 322 ms 23928 KB Output is correct
12 Correct 36 ms 23936 KB Output is correct
13 Correct 27 ms 23808 KB Output is correct
14 Correct 38 ms 23808 KB Output is correct
15 Correct 19 ms 23808 KB Output is correct
16 Correct 21 ms 23808 KB Output is correct
17 Correct 150 ms 23868 KB Output is correct
18 Correct 85 ms 23808 KB Output is correct
19 Correct 20 ms 23808 KB Output is correct
20 Correct 25 ms 23808 KB Output is correct
21 Correct 230 ms 23928 KB Output is correct
22 Execution timed out 1594 ms 23936 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 21 ms 23808 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 23 ms 23808 KB Output is correct
5 Correct 29 ms 23808 KB Output is correct
6 Correct 24 ms 23808 KB Output is correct
7 Correct 290 ms 23928 KB Output is correct
8 Correct 405 ms 23808 KB Output is correct
9 Correct 130 ms 23868 KB Output is correct
10 Correct 31 ms 23808 KB Output is correct
11 Correct 322 ms 23928 KB Output is correct
12 Correct 36 ms 23936 KB Output is correct
13 Correct 27 ms 23808 KB Output is correct
14 Correct 38 ms 23808 KB Output is correct
15 Correct 19 ms 23808 KB Output is correct
16 Correct 21 ms 23808 KB Output is correct
17 Correct 150 ms 23868 KB Output is correct
18 Correct 85 ms 23808 KB Output is correct
19 Correct 20 ms 23808 KB Output is correct
20 Correct 25 ms 23808 KB Output is correct
21 Correct 230 ms 23928 KB Output is correct
22 Execution timed out 1594 ms 23936 KB Time limit exceeded
23 Halted 0 ms 0 KB -