Submission #344590

#TimeUsernameProblemLanguageResultExecution timeMemory
344590DavidZ122Traffic (IOI10_traffic)C++14
0 / 100
17 ms24812 KiB
#include <bits/stdc++.h> //#include "traffic.h" using namespace std; typedef vector<int> vi; typedef vector<pair<int,int>> vpi; typedef long long ll; #define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define F1R(i,a) FOR(i,1,a) #define ROF(i,a,b) for ( i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) #define rsz resize #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define f first #define s second #define mp make_pair #define pb push_back void setIO(string name = "") { ios_base::sync_with_stdio(0); cin.tie(0); if (sz(name)) { freopen((name+".in").c_str(), "r", stdin); freopen((name+".out").c_str(), "w", stdout); } } bool cmp(const pair<pair<int,int>,int>&a, const pair<pair<int,int>,int> &b) { return a.s>b.s; } bool cmp2(const pair<pair<int,int>,int>&a, const pair<pair<int,int>,int> &b) { return a.f.s>b.f.s; } const int SZ=1e6+1; const int MOD=1e9+7; vi adj[SZ]; bool vis[SZ]; ll dfs(int node, int P[]) { vis[node]=1; ll ans=P[node]; trav(x, adj[node]) { if(!vis[x]) ans+=dfs(x, P); } return ans; } ll solve(int node, int P[]) { ll m=INT_MAX; trav(x, adj[node]) { m=fmin(m, dfs(x, P)); } return m; } int LocateCentre(int N,int P[],int S[], int D[]) { FIO; for(int i=0; i<N-1; i++) { adj[S[i]].pb(D[i]); adj[D[i]].pb(S[i]); } ll ans=0, ansMin=INT_MAX; F0R(i, N) { memset(vis, 0, SZ); ll a=solve(i, P); if(a<ansMin) { ans=i; ansMin=a; } } return ans+1; } //int main() { // int P[5] = {10,10,10,20,20}; // int S[4] = {1, 2, 2, 3}; // int D[4] = {2, 0, 3, 4}; // cout << LocateCentre(5, P, S, D); // }

Compilation message (stderr)

traffic.cpp: In function 'void setIO(std::string)':
traffic.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   26 |         freopen((name+".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
traffic.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   27 |         freopen((name+".out").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...