Submission #210940

#TimeUsernameProblemLanguageResultExecution timeMemory
210940HNO2Designated Cities (JOI19_designated_cities)C++17
7 / 100
355 ms39288 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=2e5+7; const int inf=INT_MAX; const ll inff=1e18; const ll mod=1e9+7; #define pii pair<int,int> #define mkp make_pair #define F first #define S second #define pb push_back #define sz(v) ((int)(v).size()) #define all(v) (v).begin(),(v).end() #define int ll #ifdef HNO2 #define IOS #else #define endl '\n' #define IOS ios::sync_with_stdio(0); cin.tie(0); #endif // HNO2 int x[maxn*2],y[maxn*2],w[maxn*2]; vector <int> G[maxn]; int ans[maxn]; int tmpsum=0; void dfs(int now,int p) { for (int i:G[now]) if ((x[i]^y[i]^now)!=p) { ans[1]+=w[i]; dfs((x[i]^y[i]^now),now); } } void dfs2(int now,int p) { ans[1]=min(ans[1],tmpsum); for (int i:G[now]) if ((x[i]^y[i]^now)!=p) { tmpsum-=(w[i]-w[i^1]); dfs2((x[i]^y[i]^now),now); tmpsum+=(w[i]-w[i^1]); } } int32_t main() { IOS int n; cin>>n; for (int i=1;i<=n;i++) ans[i]=inff; int _=0; for (int i=1;i<=n-1;i++) { int X,Y,Z,W; cin>>X>>Y>>Z>>W; x[_]=X,y[_]=Y,w[_]=Z; x[_^1]=Y,y[_^1]=X,w[_^1]=W; G[X].pb(_); G[Y].pb(_^1); _+=2; } //1: calculate ans[1] ans[1]=0; dfs(1,-1); tmpsum=ans[1]; dfs2(1,-1); // //2: ans[2] // //2: using ans[2] to calculate ans[i] // int q; cin>>q; while (q--) { int X; cin>>X; cout<<ans[X]<<endl; } // }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...