Submission #669586

# Submission time Handle Problem Language Result Execution time Memory
669586 2022-12-06T19:40:27 Z dozer Spring cleaning (CEOI20_cleaning) C++14
0 / 100
290 ms 9120 KB
#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define sp " "
#define endl "\n"
#define pii pair<int, int>
#define st first
#define nd second
#define N 100005


vector<int> adj[N];
int val[N], par[N], deg[N], sum[N], dist[N];
int ans;

int dfs(int node, int root)
{
    int flag = 0;
    par[node] = root;
    for (auto i : adj[node])
    {
        if (i != root) flag ^= dfs(i, node);
    }
    if (adj[node].size() == 1) flag ^= 1;
    val[node] = flag;
    if (flag == 0) val[node] = 2;
    ans += val[node];
    cout<<node<<sp<<flag<<endl;
    return flag;
}

void dfs2(int node, int root, int d, int dd)
{
    sum[node] = d + val[node];
    dist[node] = dd;
    for (auto i : adj[node])
    {
        if (i != root) dfs2(i, node, d + val[node], dd + 1);
    }
}

int32_t main()
{
    //fastio();
    int n, q;
    cin>>n>>q;
    for (int i = 1; i < n; i++)
    {
        int u, v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    int flag = dfs(1, 0);
    dfs2(1, 0, -val[1], 0);
    while(q--)
    {
        int d;
        cin>>d;
        int node;
        cin>>node;
        if (adj[node].size() != 1) flag ^= 1;
        int tmp = ans + 1;
        if (adj[node].size() != 1)
        {
            tmp -= sum[node];
            tmp += 3 * dist[node] - sum[node];
        }
        if (flag) cout<<-1<<endl;
        else cout<<tmp<<endl;
        if (adj[node].size() != 1) flag ^= 1;
    }
    
    
    cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 3284 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 4384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 180 ms 6724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 290 ms 9120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -