#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 5e2 + 10;
struct EDGE{
int to , id;
};
int n , m , col[N];
vector <EDGE> adj[N];
vector <int> r;
bool marked[N] , dead[N] , vis[N] , is_cand[N];
int Find_good(int v)
{
marked[v] = true;
for(auto u : adj[v]) if(!marked[u.to])
return Find_good(u.to);
return v;
}
void Dfs(int v)
{
marked[v] = true;
for(auto u : adj[v]) if(!marked[u.to] && !dead[u.to])
{
r.push_back(u.id);
col[u.to] = col[v];
Dfs(u.to);
}
}
vector<int> find_roads(int nn, vector<int> u, vector<int> v) {
n = nn;
m = u.size();
for(int i = 0 ; i < m ; i++)
{
adj[u[i]].push_back({v[i] , i});
adj[v[i]].push_back({u[i] , i});
}
int star = Find_good(0);
vector <int> cand;
dead[star] = true;
is_cand[star] = true;
cand.push_back(star);
vector <int> cor;
//cout << "STAR " << star << endl;
while(!cand.empty())
{
int mx = 0;
vector <EDGE> add;
vector <int> rem;
r = cor;
for(int i = 0 ; i < n ; i++)
{
marked[i] = false;
vis[i] = false;
}
int coco = 0;
for(int i = 0 ; i < n ; i++) if(!dead[i] && !marked[i])
{
col[i] = coco;
Dfs(i);
coco++;
////cout << i << endl;
}
////cout << "WTF " << endl;
for(int asd = 0 ; asd < coco ; asd++)
{
vector <EDGE> fake;
for(int i = 0 ; i < coco ; i++)
vis[i] = false;
for(auto v : cand) for(auto u : adj[v]) if(!dead[u.to] && col[u.to] != asd && !vis[col[u.to]])
{
r.push_back(u.id);
vis[col[u.to]] = true;
}
for(auto v : cand) for(auto u : adj[v]) if(!dead[u.to] && col[u.to] == asd)
{
r.push_back(u.id);
//for(auto i : r)
//cout << i << " ";
int now = count_common_roads(r);
//cout << " ? " << endl;
//cout << now << endl;
if(now > mx)
{
mx = now;
fake.clear();
}
if(now == mx)
fake.push_back(u);
r.pop_back();
}
for(int i = 0 ; i < coco - 1 ; i++)
r.pop_back();
for(auto u : fake)
add.push_back(u);
}
cand.clear();
for(auto u : add)
{
cor.push_back(u.id);
dead[u.to] = true;
cand.push_back(u.to);
}
}
return cor;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
correct |
2 |
Correct |
0 ms |
600 KB |
correct |
3 |
Correct |
0 ms |
344 KB |
correct |
4 |
Correct |
0 ms |
348 KB |
correct |
5 |
Correct |
1 ms |
604 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
344 KB |
correct |
8 |
Correct |
0 ms |
348 KB |
correct |
9 |
Correct |
0 ms |
348 KB |
correct |
10 |
Correct |
0 ms |
348 KB |
correct |
11 |
Correct |
0 ms |
348 KB |
correct |
12 |
Correct |
0 ms |
348 KB |
correct |
13 |
Correct |
0 ms |
348 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
correct |
2 |
Correct |
0 ms |
600 KB |
correct |
3 |
Correct |
0 ms |
344 KB |
correct |
4 |
Correct |
0 ms |
348 KB |
correct |
5 |
Correct |
1 ms |
604 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
344 KB |
correct |
8 |
Correct |
0 ms |
348 KB |
correct |
9 |
Correct |
0 ms |
348 KB |
correct |
10 |
Correct |
0 ms |
348 KB |
correct |
11 |
Correct |
0 ms |
348 KB |
correct |
12 |
Correct |
0 ms |
348 KB |
correct |
13 |
Correct |
0 ms |
348 KB |
correct |
14 |
Correct |
1 ms |
348 KB |
correct |
15 |
Correct |
0 ms |
348 KB |
correct |
16 |
Correct |
1 ms |
348 KB |
correct |
17 |
Correct |
1 ms |
348 KB |
correct |
18 |
Correct |
1 ms |
348 KB |
correct |
19 |
Correct |
1 ms |
348 KB |
correct |
20 |
Correct |
1 ms |
348 KB |
correct |
21 |
Correct |
1 ms |
508 KB |
correct |
22 |
Incorrect |
1 ms |
348 KB |
WA in grader: NO |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
correct |
2 |
Correct |
0 ms |
600 KB |
correct |
3 |
Correct |
0 ms |
344 KB |
correct |
4 |
Correct |
0 ms |
348 KB |
correct |
5 |
Correct |
1 ms |
604 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
344 KB |
correct |
8 |
Correct |
0 ms |
348 KB |
correct |
9 |
Correct |
0 ms |
348 KB |
correct |
10 |
Correct |
0 ms |
348 KB |
correct |
11 |
Correct |
0 ms |
348 KB |
correct |
12 |
Correct |
0 ms |
348 KB |
correct |
13 |
Correct |
0 ms |
348 KB |
correct |
14 |
Correct |
1 ms |
348 KB |
correct |
15 |
Correct |
0 ms |
348 KB |
correct |
16 |
Correct |
1 ms |
348 KB |
correct |
17 |
Correct |
1 ms |
348 KB |
correct |
18 |
Correct |
1 ms |
348 KB |
correct |
19 |
Correct |
1 ms |
348 KB |
correct |
20 |
Correct |
1 ms |
348 KB |
correct |
21 |
Correct |
1 ms |
508 KB |
correct |
22 |
Incorrect |
1 ms |
348 KB |
WA in grader: NO |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
correct |
2 |
Correct |
0 ms |
348 KB |
correct |
3 |
Incorrect |
61 ms |
4160 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
correct |
2 |
Correct |
0 ms |
600 KB |
correct |
3 |
Correct |
0 ms |
344 KB |
correct |
4 |
Correct |
0 ms |
348 KB |
correct |
5 |
Correct |
1 ms |
604 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
344 KB |
correct |
8 |
Correct |
0 ms |
348 KB |
correct |
9 |
Correct |
0 ms |
348 KB |
correct |
10 |
Correct |
0 ms |
348 KB |
correct |
11 |
Correct |
0 ms |
348 KB |
correct |
12 |
Correct |
0 ms |
348 KB |
correct |
13 |
Correct |
0 ms |
348 KB |
correct |
14 |
Correct |
1 ms |
348 KB |
correct |
15 |
Correct |
0 ms |
348 KB |
correct |
16 |
Correct |
1 ms |
348 KB |
correct |
17 |
Correct |
1 ms |
348 KB |
correct |
18 |
Correct |
1 ms |
348 KB |
correct |
19 |
Correct |
1 ms |
348 KB |
correct |
20 |
Correct |
1 ms |
348 KB |
correct |
21 |
Correct |
1 ms |
508 KB |
correct |
22 |
Incorrect |
1 ms |
348 KB |
WA in grader: NO |
23 |
Halted |
0 ms |
0 KB |
- |