Submission #124037

#TimeUsernameProblemLanguageResultExecution timeMemory
124037mechfrog88City Mapping (NOI18_citymapping)C++14
57 / 100
121 ms13068 KiB
#include "citymapping.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; struct node{ ll a,b,w; bool operator <(const node& rhs) const{ return w < rhs.w; } }; vector <ll> id; ll find(ll i){ if (id[i] < 0) return i; return id[i] = find(id[i]); } void unio(ll i,ll j){ ll a = find(i); ll b = find(j); if (a == b) return; if (id[b] < id[a]) swap(a,b); id[a] += id[b]; id[b] = a; } void find_roads(int n, int q, int a[], int b[], int w[]) { vector <node> arr; if (q == 12000){ for (int z=2;z<=n;z++){ node temp; temp.a = 1; temp.b = z; temp.w = get_distance(1,z); arr.push_back(temp); } sort(arr.begin(),arr.end()); ll left = 0; ll right = 0; ll leftpos = 1; ll rightpos = 1; ll c = 0; for (int z=0;z<n-1;z++){ ll temp = get_distance(leftpos,arr[z].b); if (left+temp == arr[z].w){ left += temp; a[c] = leftpos; b[c] = arr[z].b; w[c] = temp; leftpos = arr[z].b; c++; continue; } temp = get_distance(rightpos,arr[z].b); if (right+temp == arr[z].w){ right += temp; a[c] = rightpos; b[c] = arr[z].b; w[c] = temp; rightpos = arr[z].b; c++; continue; } } return; } for (int z=1;z<=n;z++){ for (int x=z+1;x<=n;x++){ node temp; temp.a = z; temp.b = x; temp.w = get_distance(z,x); arr.push_back(temp); } } id.resize(n+1,-1); sort(arr.begin(),arr.end()); vector <ll> count(n+1,0); ll c = 0; for (int z=0;z<arr.size();z++){ if (count[arr[z].a] >= 3 || count[arr[z].b] >= 3) continue; ll i = find(arr[z].a); ll j = find(arr[z].b); if (i == j) continue; unio(i,j); a[c] = arr[z].a; b[c] = arr[z].b; w[c] = arr[z].w; count[arr[z].a]++; count[arr[z].b]++; c++; } return; }

Compilation message (stderr)

citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:80:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int z=0;z<arr.size();z++){
               ~^~~~~~~~~~~
#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...