Submission #839927

# Submission time Handle Problem Language Result Execution time Memory
839927 2023-08-30T21:17:02 Z pere_gil Longest Trip (IOI23_longesttrip) C++17
5 / 100
1000 ms 608 KB
#include "longesttrip.h"
#include "bits/stdc++.h"
using namespace std;

#define vi vector<int>
#define ii pair<int,int>

const int mxn=257;
vector<int> adj[mxn];

ii dfs(int u, vector<bool> &vis, vi &res, bool sw){
  vis[u]=true;
  ii best={0,u};
  int nxt=u;
  for(int v: adj[u]){
    if(vis[v]) continue;
    ii act=dfs(v,vis,res,sw);
    if(act.first+1>best.first) best={act.first+1,act.second},nxt=v;
  }
  
  if(sw && nxt!=u) res.push_back(nxt);
  
  return best;
}

vi longest_trip(int n, int d){
  for(int i=0;i<mxn;i++) adj[i].clear();
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
      if(are_connected({i},{j}))
	adj[i].push_back(j),adj[j].push_back(i);

  vector<bool> first(n,false),second(n,false);
  vector<int> res;
  for(int i=0;i<n;i++){
    if(first[i]) continue;
    vi act;
    int st=dfs(i,first,act,false).second;
    dfs(st,second,act,true);
    act.push_back(st);
    reverse(res.begin(),res.end());

    if(act.size()>res.size()) res=act;
  }
  
  return res;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 222 ms 568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 208 KB Output is correct
2 Correct 40 ms 208 KB Output is correct
3 Correct 225 ms 316 KB Output is correct
4 Correct 428 ms 336 KB Output is correct
5 Correct 905 ms 568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 208 KB Output is correct
2 Correct 33 ms 208 KB Output is correct
3 Correct 199 ms 324 KB Output is correct
4 Correct 444 ms 320 KB Output is correct
5 Correct 839 ms 564 KB Output is correct
6 Correct 10 ms 208 KB Output is correct
7 Correct 38 ms 208 KB Output is correct
8 Correct 195 ms 308 KB Output is correct
9 Correct 275 ms 332 KB Output is correct
10 Execution timed out 1018 ms 568 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 208 KB Output is correct
2 Correct 33 ms 208 KB Output is correct
3 Correct 209 ms 208 KB Output is correct
4 Correct 545 ms 344 KB Output is correct
5 Correct 854 ms 576 KB Output is correct
6 Correct 9 ms 208 KB Output is correct
7 Correct 30 ms 208 KB Output is correct
8 Correct 200 ms 328 KB Output is correct
9 Correct 431 ms 320 KB Output is correct
10 Correct 907 ms 576 KB Output is correct
11 Correct 953 ms 572 KB Output is correct
12 Correct 850 ms 608 KB Output is correct
13 Correct 917 ms 592 KB Output is correct
14 Correct 8 ms 208 KB Output is correct
15 Correct 21 ms 208 KB Output is correct
16 Incorrect 9 ms 208 KB Incorrect
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 208 KB Output is correct
2 Correct 42 ms 208 KB Output is correct
3 Partially correct 157 ms 328 KB Output is partially correct
4 Partially correct 398 ms 332 KB Output is partially correct
5 Partially correct 795 ms 576 KB Output is partially correct
6 Correct 10 ms 208 KB Output is correct
7 Correct 43 ms 208 KB Output is correct
8 Partially correct 224 ms 324 KB Output is partially correct
9 Partially correct 395 ms 324 KB Output is partially correct
10 Partially correct 860 ms 584 KB Output is partially correct
11 Partially correct 986 ms 608 KB Output is partially correct
12 Execution timed out 1016 ms 580 KB Time limit exceeded
13 Halted 0 ms 0 KB -