# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
147500 | JovanK26 | City Mapping (NOI18_citymapping) | C++14 | 110 ms | 7780 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "citymapping.h"
#include<bits/stdc++.h>
using namespace std;
struct edge
{
int a;
int b;
int w;
};
vector<edge> edg;
bool cmp(edge i,edge j)
{
return i.w<j.w;
}
bool vis[1001][1001];
int prt[1001];
int sz[1001];
int findd(int x)
{
while(prt[x]!=x)
{
x=prt[x];
}
return x;
}
void unionn(int x,int y)
{
x=findd(x);
y=findd(y);
if(sz[x]<sz[y])swap(x,y);
prt[y]=x;
sz[x]+=sz[y];
}
void find_roads(int N, int Q, int A[], int B[], int W[]) {
int br=0;
for(int i=0;i<=N;i++)
{
prt[i]=i;
sz[i]=1;
}
for(int i=1;i<=N;i++)
{
for(int j=1;j<=N;j++)
{
if(i==j)continue;
if(vis[i][j] || vis[j][i])continue;
vis[i][j]=1;
vis[j][i]=1;
long long temp=get_distance(i,j);
edge tmp;
tmp.a=i;
tmp.b=j;
tmp.w=temp;
edg.push_back(tmp);
}
}
sort(edg.begin(),edg.end(),cmp);
for(int i=0;i<edg.size();i++)
{
if(findd(edg[i].a)==findd(edg[i].b))
{
unionn(edg[i].a,edg[i].b);
A[br]=edg[i].a;
B[br]=edg[i].b;
W[br]=edg[i].w;
br++;
}
}
return;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |