Submission #964667

#TimeUsernameProblemLanguageResultExecution timeMemory
9646678pete8City Mapping (NOI18_citymapping)C++17
25 / 100
208 ms868 KiB
#include "citymapping.h" #include<iostream> #include<stack> #include<map> #include<vector> #include<string> #include<unordered_map> #include <queue> #include<cstring> #include<limits.h> #include <cassert> #include<cmath> #include<set> #include<algorithm> #include <iomanip> #include<numeric> //gcd(a,b) #include<bitset> #include <cstdlib> #include <cstdint> using namespace std; #define ll long long #define f first //#define endl "\n" #define s second #define pii pair<int,int> #define ppii pair<int,pii> #define vi vector<int> #define pb push_back #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define F(n) for(int i=0;i<n;i++) #define lb lower_bound #define ub upper_bound #define fastio ios::sync_with_stdio(false);cin.tie(NULL); #pragma GCC optimize ("03,unroll-loops") using namespace std; #define int long long //#define double long double const int mxn=2e3,inf=1e18; vector<int>on; int sz[mxn+10],del[mxn+10]; vector<pair<pii,int>>e; vector<pii>adj[mxn+10]; vector<int>von; int cnt=0; void getsz(int cur,int p){ sz[cur]=1; cnt++; for(auto i:adj[cur]){ if(del[i.s]||i.f==p)continue; on.pb(i.s); getsz(i.f,cur); sz[cur]+=sz[i.f]; } } int qnode,last; void solve(int node){ on.clear(); cnt=0; getsz(node,-1); pii ed={inf,-1}; if(on.empty()){ if(last==inf)last=get_distance(node,qnode); e.pb({{node,qnode},last}); adj[node].pb({qnode,e.size()-1}); adj[qnode].pb({node,e.size()-1}); return; } for(auto i:on){ if(sz[e[i].f.f]>sz[e[i].f.s])swap(e[i].f.f,e[i].f.s); ed=min(ed,{abs(sz[e[i].f.f]-cnt+sz[e[i].f.s]),i}); } del[ed.s]=1; int x=get_distance(e[ed.s].f.f,qnode),y=get_distance(e[ed.s].f.s,qnode); last=min(x,y); if(x<y)solve(e[ed.s].f.f); else solve(e[ed.s].f.s); } void find_roads(int32_t n, int32_t q, int32_t A[], int32_t B[], int32_t W[]){ srand(time(NULL)); int st=rand()%n; st++; vector<pii>o; for(int i=1;i<=n;i++)if(i!=st)o.pb({get_distance(i,st),i}); sort(all(o)); for(auto i:o){ qnode=i.s; last=inf; for(int j=0;j<e.size();j++)del[j]=0; solve(st); } for(int i=0;i<e.size();i++)A[i]=e[i].f.f,B[i]=e[i].f.s,W[i]=e[i].s; return; }

Compilation message (stderr)

citymapping.cpp: In function 'void find_roads(int32_t, int32_t, int32_t*, int32_t*, int32_t*)':
citymapping.cpp:89:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |   for(int j=0;j<e.size();j++)del[j]=0;
      |               ~^~~~~~~~~
citymapping.cpp:92:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |  for(int i=0;i<e.size();i++)A[i]=e[i].f.f,B[i]=e[i].f.s,W[i]=e[i].s;
      |              ~^~~~~~~~~
#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...