답안 #480291

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
480291 2021-10-15T14:16:14 Z MOUF_MAHMALAT Zagrade (COI17_zagrade) C++14
10 / 100
8 ms 7372 KB
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define F first
#define S second
using namespace std;
typedef int ll;
ll n,x,y,b[1009],ans;
char c;
vector<vector<ll> >v;
void dfs(ll d,ll p,ll sum)
{
    if(sum<0)
        return;
    if(sum==0)
        ans++;
    for(auto z:v[d])
        if(z!=p)
            dfs(z,d,sum+b[z]);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n;
    v.resize(n+1);
    for(ll i=1; i<=n; i++)
    {
        cin>>c;
        if(c=='(')
            b[i]=1;
        else
            b[i]=-1;
    }
    for(ll i=1; i<n; i++)
    {
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(ll i=1;i<=n;i++)
        dfs(i,i,b[i]);
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 332 KB Output is correct
2 Correct 7 ms 332 KB Output is correct
3 Correct 6 ms 332 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 4 ms 320 KB Output is correct
6 Correct 8 ms 352 KB Output is correct
7 Correct 6 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 6 ms 332 KB Output is correct
10 Correct 4 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 7372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 332 KB Output is correct
2 Correct 7 ms 332 KB Output is correct
3 Correct 6 ms 332 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 4 ms 320 KB Output is correct
6 Correct 8 ms 352 KB Output is correct
7 Correct 6 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 6 ms 332 KB Output is correct
10 Correct 4 ms 320 KB Output is correct
11 Incorrect 5 ms 7372 KB Output isn't correct
12 Halted 0 ms 0 KB -