# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1041663 |
2024-08-02T06:50:44 Z |
vjudge1 |
Izlet (COI19_izlet) |
C++17 |
|
362 ms |
36452 KB |
/*
بسم الله الرحمن الرحيم
Author:
(:Muhammad Aneeq:)
*/
#include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;
int const N=3e3+10;
int par[N]={};
vector<int>nei[N]={};
int pa[N]={};
vector<int>mem[N]={};
int a[N][N]={};
int an[N]={};
int root(int n)
{
if (par[n]==n) return n;
return (par[n]=root(par[n]));
}
set<int>s;
map<int,int>cnt;
void dfs(int u,int root=-1,int v=-1)
{
if (root==-1)
root=u;
if (a[root][u]==s.size())
{
an[u]=an[root];
}
s.insert(an[u]);
cnt[an[u]]++;
for (auto i:nei[u])
{
if (i!=v)
dfs(i,root,u);
}
cnt[an[u]]--;
if (cnt[an[u]]==0)
s.erase(an[u]);
}
inline void solve()
{
int subt;
cin>>subt;
int n;
cin>>n;
for (int i=0;i<n;i++)
par[i]=i,mem[i].push_back(i);
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
cin>>a[i][j];
vector<vector<int>>ans;
for (int i=0;i<n;i++)
{
for (int j=i+1;j<n;j++)
{
if (a[i][j]==1)
{
int a=i,b=j;
a=root(a),b=root(b);
if (a==b)
continue;
par[b]=a;
ans.push_back({a,b});
for (auto i:mem[b])
mem[a].push_back(i);
mem[b]={};
}
}
}
vector<int>z;
for (int i=1;i<n;i++)
if (root(i)==i)
z.push_back(i);
vector<int>f;
f.push_back(0);
map<int,vector<int>>id;
for (auto i:z)
id[a[0][i]].push_back(i);
pa[0]=-1;
for (auto i:id)
{
for (auto j:i.second)
{
for (auto k:f)
{
int z=k,req=2;
while (z!=-1&&a[j][z]==req)
{
req++,z=pa[z];
}
if (z==-1)
{
pa[j]=k;
nei[k].push_back(j);
nei[j].push_back(k);
ans.push_back({j,k});
break;
}
}
}
f=i.second;
}
z.push_back(0);
for (auto i:z)
an[i]=i+1;
an[0]=1;
for (auto i:z)
{
s={},cnt.clear();
dfs(i);
}
for (auto i:z)
{
for (auto j:mem[i])
an[j]=an[i];
}
for (int i=0;i<n;i++)
cout<<an[i]<<' ';
cout<<endl;
for (auto i:ans)
cout<<i[0]+1<<' '<<i[1]+1<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
solve();
}
Compilation message
izlet.cpp: In function 'void dfs(int, int, int)':
izlet.cpp:30:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | if (a[root][u]==s.size())
| ~~~~~~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
362 ms |
36452 KB |
Output is correct |
3 |
Correct |
346 ms |
36176 KB |
Output is correct |
4 |
Correct |
262 ms |
36204 KB |
Output is correct |
5 |
Correct |
312 ms |
36432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
260 ms |
35924 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
362 ms |
36452 KB |
Output is correct |
3 |
Correct |
346 ms |
36176 KB |
Output is correct |
4 |
Correct |
262 ms |
36204 KB |
Output is correct |
5 |
Correct |
312 ms |
36432 KB |
Output is correct |
6 |
Incorrect |
260 ms |
35924 KB |
Unexpected end of file - int32 expected |
7 |
Halted |
0 ms |
0 KB |
- |