Submission #463568

#TimeUsernameProblemLanguageResultExecution timeMemory
463568KhizriTraffic (IOI10_traffic)C++17
50 / 100
5060 ms29860 KiB
#include "traffic.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define F first #define S second #define INF 1e18 #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define pii pair<int,int> #define pll pair<ll,ll> #define OK cout<<"Ok"<<endl; #define MOD (ll)(1e9+7) #define endl "\n" const int mxn=1e6+5; int a[mxn],b[mxn],node; vector<int>vt[mxn]; ll dfs(int u,int p,int arr[]){ ll ans=0; for(int v:vt[u]){ if(v!=p){ if(u!=node){ ans+=dfs(v,u,arr); } else{ ans=max(ans,dfs(v,u,arr)); } } } return ans+arr[u]; } int LocateCentre(int n, int arr[], int S[], int D[]) { bool q=true; for(int i=0;i<n-1;i++){ if(S[i]!=i||D[i]!=i+1){ q=false; } } for(int i=0;i<n-1;i++){ vt[S[i]].pb(D[i]); vt[D[i]].pb(S[i]); } ll maxs=INF,kk=0; for(int i=0;i<n;i++){ node=i; ll sum=dfs(i,-1,arr)-arr[i]; if(sum<maxs){ maxs=sum; kk=i; } } return kk; }

Compilation message (stderr)

traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:34:7: warning: variable 'q' set but not used [-Wunused-but-set-variable]
   34 |  bool q=true;
      |       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...