Submission #1117440

#TimeUsernameProblemLanguageResultExecution timeMemory
1117440FucKanhSynchronization (JOI13_synchronization)C++14
0 / 100
8061 ms16968 KiB
#include<bits/stdc++.h>
#define ll long long
#define int ll
#define pii pair<int,int>

using namespace std;

const int maxn = 1e5 + 2;
const int LG = 18;

int vst[maxn],tout[maxn],h[maxn],active[maxn],val[maxn], valid[maxn];
int pa[maxn][LG + 2];
pii e[maxn];
vector<pii> a[maxn];
int n,m,q,T;

void dfs(int u, int va) {
    vst[u] = 1;
    val[u] = va;
    for (pii tmp : a[u]) {
        int v,id; tie(v,id) = tmp;
        if (active[id]) {
            if (vst[v]==0) {
                dfs(v,va);
            }
        }
    }
}

void solve() {
    cin >> n >> m >> q;

    for (int i = 1; i <= n; i++) val[i]= 1;
    for (int i = 1; i < n; i++) {
        int x,y; cin >> x >> y;
        a[x].push_back({y,i});
        a[y].push_back({x,i});
        e[i] = {x,y};
    }

    for (int i = 1; i <= m; i++) {
        int id; cin >> id;
        if (!active[id]) {
            int u,v; tie(u,v) = e[id];
            int du = val[v] - valid[id];
            int dv = val[u] - valid[id];
            memset(vst,0,sizeof(int)*(n+2));
            dfs(u,val[u] + du);
            memset(vst,0,sizeof(int)*(n+2));
            dfs(v,val[v] + dv);
            valid[id] = val[v];
            assert(val[v]==val[u]);
        }
        active[id] = !active[id];
    }

    for (int i = 1; i <= q; i++) {
        int x; cin >> x;
        cout << val[x] << '\n';
    }
}
void file(string name) {
    if (fopen((name + ".inp").c_str(), "r")) {
        freopen((name + ".inp").c_str(), "r", stdin);
        freopen((name + ".ans").c_str(), "w", stdout);
    }
}
signed main() {
    file("B");
    cin.tie(0) -> sync_with_stdio(0);
    solve();
    return 0;
}

Compilation message (stderr)

synchronization.cpp: In function 'void file(std::string)':
synchronization.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen((name + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen((name + ".ans").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...