# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1119095 | kiethm07 | Synchronization (JOI13_synchronization) | C++11 | 8053 ms | 13384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pli pair<long long,int>
#define plii pair<long long,pii>
#define fi first
#define se second
#define vi vector<int>
#define vii vector<pii>
#define all(x) x.begin(),x.end()
#define compact(x) x.erase(unique(all(x)),x.end())
#define pb(x) push_back(x)
using namespace std;
typedef long long ll;
typedef long double ld;
const int inf = 1e9;
const ll linf = 1e16;
const double PI = acos(-1);
const int N = 1e5 + 5;
struct edge{
int u,v,w;
edge(){}
edge(int a,int b,int c){
u = a,v = b,w = c;
}
};
edge e[N];
vector<int> a[N];
int n,m,q;
int pa[N];
bool active[N];
int val[N];
void dfs(int u,int p){
for (int v : a[u]){
if (v == p) continue;
pa[v] = u;
dfs(v,u);
}
}
int getNode(int u){
while(active[pa[u]]) u = pa[u];
return u;
}
void query(int id){
if (e[id].v == pa[e[id].u]) swap(e[id].u, e[id].v);
int u = e[id].u;
int v = e[id].v;
int f = getNode(u);
int tmp = val[f] + val[v] - e[id].w;
val[f] = val[v] = e[id].w = tmp;
active[v] ^= 1;
}
int main(){
#define TEXT "synchronization"
cin.tie(0) -> sync_with_stdio(0);
if (fopen(TEXT".inp","r")){
freopen(TEXT".inp","r",stdin);
freopen(TEXT".ans","w",stdout);
}
cin >> n >> m >> q;
for (int i = 1; i < n; i++){
int u,v;
cin >> u >> v;
a[u].push_back(v);
a[v].push_back(u);
e[i] = edge(u,v,0);
}
dfs(1,-1);
while(m--){
int id;
cin >> id;
query(id);
}
while(q--){
int x;
cin >> x;
int f = getNode(x);
cout << val[f] << "\n";
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |