#include <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;
#define pb push_back
#define fi first
#define se second
const int nax = 2e5+5;
const int MOD = 1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int> adj[256];
bool vis[256];
set<int> components[256];
void dfs(int x,int p){
components[p].insert(x);
vis[x]=true;
for(auto u:adj[x]){
if(vis[u]) continue;
dfs(u,p);
}return;
}
std::vector<int> longest_trip(int N, int D)
{
vector<int> a,b;
for (int i = 0; i < N; ++i)
{
vis[i]=0;
adj[i].clear();
components[i].clear();
}
for (int i = 0; i < N; ++i)
{
for (int j = i+1; j < N; ++j)
{
if(are_connected({i},{j})){
adj[i].pb(j);
adj[j].pb(i);
}else{
a.pb(i);
b.pb(j);
}
}
}
pair<int,int> big={-1,-1};
int cnt=0;
for (int i = 0; i < N; ++i)
{
if(vis[i]) continue;
cnt++;
dfs(i,i);
if(big.fi<(int)components[i].size()){
big={(int)components[i].size(),i};
}
}
vector<int> ans;
shuffle(a.begin(),a.end(),rng);
shuffle(b.begin(),b.end(),rng);
if(a.size()==0){
for (int i = 0; i < N; ++i)
{
ans.pb(i);
}
}else if(cnt>1){
for(auto u:components[big.se]){
ans.pb(u);
}
}else{
memset(vis,0,sizeof vis);
for(auto u:a){
if(components[big.se].count(u)) {
ans.pb(u);
vis[u]=true;
}
}
for(auto u:components[big.se]){
if(!vis[u]) ans.pb(u);
}
for(auto u:b){
if(components[big.se].count(u)){
ans.pb(u);
vis[u]=true;
}
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
24 ms |
344 KB |
Output is correct |
3 |
Correct |
148 ms |
344 KB |
Output is correct |
4 |
Correct |
406 ms |
600 KB |
Output is correct |
5 |
Correct |
832 ms |
968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
344 KB |
Output is correct |
2 |
Correct |
22 ms |
344 KB |
Output is correct |
3 |
Correct |
139 ms |
344 KB |
Output is correct |
4 |
Correct |
433 ms |
744 KB |
Output is correct |
5 |
Correct |
882 ms |
892 KB |
Output is correct |
6 |
Incorrect |
1 ms |
344 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
20 ms |
344 KB |
Output is correct |
3 |
Correct |
161 ms |
344 KB |
Output is correct |
4 |
Correct |
405 ms |
344 KB |
Output is correct |
5 |
Correct |
862 ms |
792 KB |
Output is correct |
6 |
Incorrect |
0 ms |
344 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
26 ms |
344 KB |
Output is correct |
3 |
Partially correct |
139 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
416 ms |
604 KB |
Output is partially correct |
5 |
Partially correct |
882 ms |
868 KB |
Output is partially correct |
6 |
Incorrect |
0 ms |
344 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |