QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#200288 | #7343. Bicycle Race | Delay_for_five_minutes# | WA | 3ms | 10396kb | C++14 | 3.3kb | 2023-10-04 16:15:01 | 2023-10-04 16:15:04 |
Judging History
answer
#include<bits/stdc++.h>
#define maxn 100005
typedef std::tuple<int,int,int> tu;
typedef std::pair<int,int> pr;
std::vector< std::pair<int,pr> > T[maxn];
std::pair<int,pr> mx[maxn];
std::pair<int,int> t1[maxn], t2[maxn];
bool check(pr A, pr B) {
return A.first != B.first && A.first != B.second && A.second != B.first && A.second != B.second;
}
int getn(std::pair<int,int> p, int Y) {
if (p.first == Y) {
return p.second;
}
else if (p.second == Y) {
return p.first;
}
else return 0;
}
int ans[maxn];
void solve(int P,int x,int y,int z,int val) {
if (P == 1) {
mx[x] = std::max(mx[x],{val,{y,z}});
}
if (P == 2) {
if (check(mx[x].second,{y,z})) {
ans[x] = std::max(ans[x], val + mx[x].first);
}
}
if (P == 3) {
int X = mx[x].second.first, Y = mx[x].second.second;
int now = getn({y,z},Y);
if (now == X || now == 0) {
return ;
}
if (val > t1[x].first) t2[x] = t1[x], t1[x] = {val, now};
else if (val > t2[x].first) t2[x] = {val, now};
}
if (P == 4){
int X = mx[x].second.first, Y = mx[x].second.second;
int now = getn({y,z},X);
if (now == Y || now == 0) {
return ;
}
int newval = (now == t1[x].second ? t2[x].first : t1[x].first);
ans[x] = std::max(ans[x],val + newval);
}
}
void get_triangles(int n,std::vector<tu>& eg) {
std::vector< pr > e[maxn];
int d[maxn],ed[maxn];
memset(d,0,sizeof d);
memset(ed,0,sizeof ed);
for(auto v : eg) {
d[std::get<1>(v)]++;
}
for(auto v : eg) {
int x = std::get<0>(v), y = std::get<1>(v);
if (std::make_pair(d[x], x) > std::make_pair(d[y], y)) {
std::swap(x,y);
}
e[x].push_back({y,std::get<2>(v)});
}
for(int P = 1; P <= 4; P++) {
for(int u = 1; u <= n; u++) {
for(auto v : e[u]) {
ed[v.first] = v.second;
}
for(auto v : e[u]) {
for(auto w : e[v.first]) {
if (ed[w.first] > 0) {
int x = v.first, y = w.first, z = u, val = v.second + w.second + ed[w.first];
solve(P,x,y,z,val);
solve(P,y,x,z,val);
solve(P,z,x,y,val);
}
}
}
for(auto v : e[u]) {
ed[v.first] = 0;
}
}
}
}
/*
int calc(std::vector< std::pair<int,pr> >& vec) {
std::pair<int,pr> mx = {0,{0,0}};
for(auto i : vec) if (i > mx) {
mx = i;
}
int ans = -1;
for(auto i : vec) if (check(i.second,mx.second)) {
ans = std::max(ans,i.first + mx.first);
}
std::pair<int,int> t1 = {0,0}, t2 = {0,0};
int x = mx.second.first, y = mx.second.second;
for(auto i : vec) {
int now = getn(i.second,y);
if (now == x || now == 0) {
continue;
}
if (i.first > t1.first) t2 = t1, t1 = {i.first, now};
else if (i.first > t2.first) t2 = {i.first, now};
}
for(auto i : vec) {
int now = getn(i.second, x);
if (now == y || now == 0) {
continue;
}
int val = (now == t1.second ? t2.first : t1.first);
if (val == 0) continue;
ans = std::max(ans, i.first + val);
}
return ans;
}
*/
int main() {
std::ios::sync_with_stdio(0);std::cin.tie(0);
// freopen("in.txt","r",stdin);
int n,m;
std::cin >> n >> m;
std::vector<tu> eg;
for(int i=1;i<=m;i++) {
int x,y,z;
std::cin >> x >> y >> z;
eg.push_back({x,y,z});
}
for(int i = 1;i <= n; i++) {
ans[i] = -1;
}
get_triangles(n,eg);
int Ans = -1;
for(int i = 1;i <= n; i++) {
Ans = std::max(Ans,ans[i]);
}
std::cout << Ans << std::endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 9780kb
input:
6 9 1 2 3 2 3 1 3 4 2 4 5 1 3 5 7 2 5 2 1 5 3 4 6 2 5 6 1
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 10396kb
input:
6 6 1 3 2 1 2 2 2 3 4 3 4 1 3 6 6 1 4 8
output:
8
result:
wrong answer 1st numbers differ - expected: '-1', found: '8'