Submission #210789

# Submission time Handle Problem Language Result Execution time Memory
210789 2020-03-18T11:02:24 Z Blagojce Synchronization (JOI13_synchronization) C++11
0 / 100
275 ms 19060 KB
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
ll const inf = 1e9;
ll const mod = 1e9 + 7;
ld const eps = 1e-13;

int n, m, q;
vector<pii> g[100005];

int z[1000000];
int seg[1000000];
void update(int k, int l, int r, int x, int y, int zet, int add){
        z[k] += zet;
        if(r < x || y < l) return;
        if(x <= l && r <= y){
                z[k] += add;
                return;
        }
        int mid = (l + r) / 2;
        update(k * 2, l, mid, x, y, z[k], add);
        update(k * 2 + 1, mid + 1, r, x, y, z[k], add);
        z[k] = 0;
        seg[k] = max(seg[k * 2] + z[k * 2], seg[k * 2 + 1] + z[k * 2 + 1]);
}
vector<int> t[100005];
int ANS = 0;
void dfs(int u, int p, int len){
        if(seg[u] + z[u] == len){
                ANS ++;
        }
        for(auto e : g[u]){
                if(e.st == p) continue;
                for(int i = 0; i < t[e.nd].size(); i += 2){
                        update(1, 0, m, t[e.nd][i], t[e.nd][i + 1], 0, 1);
                }
                dfs(e.st, u, len + 1);
                for(int i = 0; i < t[e.nd].size(); i += 2){
                        update(1, 0, m, t[e.nd][i], t[e.nd][i + 1], 0, -1);
                }
        }
}


void solve(){
        cin >> n >> m >> q;
        fr(i, 0, n - 1){
                int u, v;
                cin >> u >> v;
                --u, --v;
                g[u].pb({v, i});
                g[v].pb({u, i});
        }
        fr(i, 0, m){
                int u;
                cin >> u;
                --u;
                t[u].pb(i);
        }
        fr(i, 0, m){
                if(t[i].size() % 2) t[i].pb(m);
        }
        if(q == 1){
                int x;
                cin >> x;
                --x;
                dfs(x, x, 0);
                cout << ANS<<endl;
        }
}

int main()
{
        solve();
        return 0;
}/*
5 6 1
1 2
1 3
2 4
2 5
1
2
1
4
4
3
1
*/

Compilation message

synchronization.cpp: In function 'void dfs(int, int, int)':
synchronization.cpp:43:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int i = 0; i < t[e.nd].size(); i += 2){
                                ~~^~~~~~~~~~~~~~~~
synchronization.cpp:47:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int i = 0; i < t[e.nd].size(); i += 2){
                                ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4984 KB Output is correct
2 Incorrect 7 ms 5112 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 275 ms 19060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 4984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 221 ms 10872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 4988 KB Output isn't correct
2 Halted 0 ms 0 KB -