Can't get this
Jun 17, 2017 at 1:08am UTC
I didn't understand exactly what this question said, nor what the editorial said also same goes for the solution e.e, can someone explain to me what exactly is going on in all 3 of these[question, editorial, solution] by relating them to each other? :c thanks alot, here are the references:
Question:
http://codeforces.com/contest/500/problem/B
Editorial part of it:
http://prntscr.com/fkqjg3
Solution code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#include<bits/stdc++.h>
using namespace std;
int n,per[400],visited[320]={0};
int a[400][400];
char x[10000];
vector<int > v1,v2;
void dfs(int i)
{
int xs;
visited[i]=1;
v1.push_back(i);
v2.push_back(per[i]);
for (xs=1;xs<=n;xs++)
{
if (a[i][xs]==1 && visited[xs]==0)
dfs(xs);
}
}
int main()
{
cin >>n;
for (int i=1;i<=n;i++)
{
scanf("%d" ,&per[i]);
}
for ( int i=1;i<=n;i++)
{
scanf("%s" ,x);
for (int j=1;j<=n;j++)
{
a[i][j]=x[j-1]-48;
}
}
for ( int i=1;i<=n;i++)
{
if (visited[i]==0)
{
dfs(i);
sort(v1.begin(),v1.end());
sort(v2.begin(),v2.end());
for (int j=0;j<v1.size();j++)
{
per[v1[j]]=v2[j];
}
v1.clear();
v2.clear();
}
}
for (int i=1;i<=n;i++)
{
printf("%d " ,per[i]);
}
printf("\n" );
return 0;
}
Topic archived. No new replies allowed.