QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#292719 | #7119. Longest Trip | Goldenglow1427 | 0 | 1ms | 4060kb | C++14 | 4.7kb | 2023-12-28 11:49:06 | 2024-04-28 09:12:53 |
Judging History
answer
/*
ID: Victor Chen [mail_vi1]
PROG: Longest Trip
LANG: C++
*/
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
const int Maxn = 300;
class Graph
{
public:
int cnt, head[Maxn+10];
struct Edge
{
int to, nxt;
}p[2*Maxn+10];
int root;
int dep[Maxn+10], fa[Maxn+10];
void AddEdge(int x, int y)
{
cnt++;
p[cnt].to = y;
p[cnt].nxt = head[x];
head[x] = cnt;
}
void dfs(int x)
{
for(int i=head[x]; i!=0; i=p[i].nxt)
if(dep[p[i].to] == 0)
{
dep[p[i].to] = dep[x] + 1;
fa[p[i].to] = x;
dfs(p[i].to);
}
}
void clear()
{
cnt = 0;
memset(head, 0, sizeof(head));
}
void init(int x)
{
root = x;
memset(dep, 0, sizeof(dep));
dep[root] = 1;
fa[root] = 0;
dfs(root);
}
}g;
int n;
bool are_connected(vector<int> A, vector<int> B);
int bg1, ed1, bg2, ed2;
vector<int> vint(int k)
{
vector<int> ret;
ret.push_back(k);
return ret;
}
vector<int> v2int(int x, int y)
{
vector<int> ret;
ret.push_back(x);
ret.push_back(y);
return ret;
}
vector<int> ret;
void dfs(int x)
{
ret.push_back(x);
for(int i=g.head[x]; i!=0; i=g.p[i].nxt)
if(g.dep[g.p[i].to] == g.dep[x] + 1)
dfs(g.p[i].to);
}
int k1, k2;
vector<int> test;
vector<int> seq1, seq2;
void dfs_seq1(int x)
{
seq1.push_back(x);
for(int i=g.head[x]; i!=0; i=g.p[i].nxt)
if(g.dep[g.p[i].to] == g.dep[x] + 1)
dfs_seq1(g.p[i].to);
}
void dfs_seq2(int x)
{
seq2.push_back(x);
for(int i=g.head[x]; i!=0; i=g.p[i].nxt)
if(g.dep[g.p[i].to] == g.dep[x] + 1)
dfs_seq2(g.p[i].to);
}
vector<int> longest_trip(int N, int D)
{
bg1 = ed1 = 0, bg2 = ed2 = 1;
for(int i=2; i<N; i++)
{
bool flag = are_connected(vint(i), vint(ed1));
if(flag)
{
g.AddEdge(ed1, i);
g.AddEdge(i, ed1);
ed1 = i;
}
else
{
flag = are_connected(vint(i), vint(ed2));
if(flag)
{
g.AddEdge(ed2, i);
g.AddEdge(i, ed2);
ed2 = i;
}
else
{
g.AddEdge(ed1, ed2);
g.AddEdge(ed2, ed1);
ed1 = bg2;
bg2 = ed2 = i;
}
}
}
bool flag = are_connected(v2int(bg1, ed1), v2int(bg2, ed2));
if(flag == true)
{
if(are_connected(vint(bg1), vint(bg2)))
{
g.AddEdge(bg1, bg2);
g.AddEdge(bg2, bg1);
g.init(ed1);
dfs(ed1);
}
else if(are_connected(vint(bg1), vint(ed2)))
{
g.AddEdge(bg1, ed2);
g.AddEdge(ed2, bg1);
g.init(ed1);
dfs(ed1);
}
else if(are_connected(vint(ed1), vint(bg2)))
{
g.AddEdge(ed1, bg2);
g.AddEdge(bg2, ed1);
g.init(bg1);
dfs(bg1);
}
else
{
g.AddEdge(ed1, ed2);
g.AddEdge(ed2, ed1);
g.init(bg1);
dfs(bg1);
}
}
else
{
g.init(bg1);
dfs(bg1);
g.init(bg2);
dfs(bg2);
int l = 0, r = seq1.size()-1;
while(l != r)
{
int mid = (l+r)/2;
test.clear();
for(int i=l; i<=mid; i++)
test.push_back(seq1[i]);
if(are_connected(test, seq2))
r = mid;
else
l = mid + 1;
}
k1 = l;
l = 0, r = seq2.size()-1;
while(l != r)
{
int mid = (l+r)/2;
test.clear();
for(int i=l; i<=mid; i++)
test.push_back(seq2[i]);
if(are_connected(test, seq1))
r = mid;
else
l = mid + 1;
}
k2 = l;
for(int i=k1+1; i<seq1.size(); i++) ret.push_back(seq1[i]);
for(int i=0; i<=k1; i++) ret.push_back(seq1[i]);
for(int i=k2; i<seq2.size(); i++) ret.push_back(seq2[i]);
for(int i=0; i<k2; i++) ret.push_back(seq2[i]);
}
return ret;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 4060kb
input:
341 3 3 1
output:
3kC2Ia2048BfyJVGojMUKKtilctlZKcB 0 1 1 2 0 3kC2Ia2048BfyJVGojMUKKtilctlZKcB 0 2 2 0 2 1 1
result:
wrong answer invalid array
Subtask #2:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 1ms
memory: 3772kb
input:
341 3 2 1
output:
3kC2Ia2048BfyJVGojMUKKtilctlZKcB 0 1 1 2 0 3kC2Ia2048BfyJVGojMUKKtilctlZKcB 0 2 2 0 2 1 1
result:
wrong answer invalid array
Subtask #3:
score: 0
Wrong Answer
Test #19:
score: 0
Wrong Answer
time: 0ms
memory: 3808kb
input:
341 3 1 1
output:
3kC2Ia2048BfyJVGojMUKKtilctlZKcB 0 1 1 2 0 3kC2Ia2048BfyJVGojMUKKtilctlZKcB 0 2 2 0 2 1 1
result:
wrong answer invalid array
Subtask #4:
score: 0
Wrong Answer
Test #83:
score: 0
Wrong Answer
time: 1ms
memory: 3836kb
input:
341 3 1 1
output:
3kC2Ia2048BfyJVGojMUKKtilctlZKcB 0 1 1 2 0 3kC2Ia2048BfyJVGojMUKKtilctlZKcB 0 2 2 0 2 1 1
result:
wrong answer invalid array