답안 #52191

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52191 2018-06-24T14:55:33 Z Smelskiy 동기화 (JOI13_synchronization) C++14
20 / 100
8000 ms 14432 KB
#include <bits/stdc++.h>
using namespace std;



int n,m,qq;
int ans;
vector<pair<int,int> > v[200005];
int f[200005];
int last[200005];
int c[200005];
int x,y;

void dfs(int x,int y,int xx,int yy) {
    if (xx<=yy) ++ans;
    for (int i=0;i<v[x].size();++i) {
        int to=v[x][i].first;
        if (to==y) continue;
        int xx2;
        int yy2=min(yy,last[v[x][i].second]);
        xx2=f[v[x][i].second];
        dfs(to,x,xx2,yy2);
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n>>m>>qq;
    for (int i=1;i<n;++i) {
        cin>>x>>y;
        v[x].push_back(make_pair(y,i));
        v[y].push_back(make_pair(x,i));
        f[i]=m+2;
        last[i]=m+1;
    }
    for (int i=1;i<=m;++i) {
        cin>>x;
        c[x]^=1;
        if (c[x]) {
            f[x]=min(f[x],i);
        } else last[x]=i;
    }
    for (int i=1;i<n;++i) {
        if (c[i]) last[i]=m+1;
    }
    for (int i=1;i<=qq;++i) {
        cin>>x;
        ans=0;
        dfs(x,-1,0,1e9);
        cout<<ans<<'\n';
    }
}

Compilation message

synchronization.cpp: In function 'void dfs(int, int, int, int)':
synchronization.cpp:16:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<v[x].size();++i) {
                  ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Incorrect 8 ms 5112 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 12212 KB Output is correct
2 Correct 57 ms 12212 KB Output is correct
3 Correct 62 ms 13772 KB Output is correct
4 Correct 62 ms 13772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 13772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 8047 ms 14432 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14432 KB Output is correct
2 Incorrect 7 ms 14432 KB Output isn't correct
3 Halted 0 ms 0 KB -