# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
419445 | NintsiChkhaidze | Zagrade (COI17_zagrade) | C++14 | 3032 ms | 26224 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int N = 300005;
int A[N],S[N];
ll res;
vector <int> v[N];
void dfs(int x,int par){
A[x] = A[par] + S[x];
if (A[x] == 0) res++;
if (A[x] < 0) return;
for (int j=0;j<v[x].size();j++){
int to = v[x][j];
if (to!=par && A[to] >= 0) dfs(to,x);
}
}
int main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n;
cin>>n;
string s;
cin>>s;
s = '$' + s;
for (int i=1;i<=n;i++)
if (s[i] == '(') S[i] = 1;
else S[i]= -1;
for (int i=1;i<n;i++){
int a,b;
cin>>a>>b;
v[a].pb(b),v[b].pb(a);
}
for (int i =1;i<=n;i++){
if (S[i] == 1) dfs(i,i);
for (int j=1;j<=n;j++)
A[j] = 0;
}
cout<<res;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |