#include<bits/stdc++.h>
#include "swap.h"
// #include"grader.cpp"
#include <vector>
#define SIZE 100010
#define MAX 2000000000
using namespace std;
struct A{
int u,w;
};
int n,sub2=1,sub1=1,cycle=1,ma=0;
A m1={MAX,MAX},m2={MAX,MAX},m3={MAX,MAX};
vector<A> g[SIZE];
void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
n=N;
for(int i=0;i<M;i++){
g[U[i]].push_back({V[i],W[i]});
g[V[i]].push_back({U[i],W[i]});
if(W[i]>ma) ma=W[i];
if(U[i]!=0) sub2=0;
if(!sub2) continue;
if(W[i]<m1.w){
m3=m2,m2=m1,m1={V[i],W[i]};
}else if(W[i]<m2.w){
m3=m2,m2={V[i],W[i]};
}else if(W[i]<m3.w){
m3={V[i],W[i]};
}
}
if(sub1){
for(int i=0;i<N;i++){
if(g[i].size()>2) sub1=0;
if(g[i].size()<2) cycle=0;
}
}
// printf("%d %d\n%d %d\n%d %d\n",m1.u,m1.w,m2.u,m2.w,m3.u,m3.w);
return ;
}
int subtask2(int X,int Y){
if(n<=3) return -1;
if(X!=0 && Y!=0){
if(X!=m1.u && Y!=m1.u){
return max(g[X][0].w,max(g[Y][0].w,m1.w));
}else if(X!=m2.u && Y!=m2.u){
return max(g[X][0].w,max(g[Y][0].w,m2.w));
}else if(X!=m3.u && Y!=m3.u){
return max(g[X][0].w,max(g[Y][0].w,m3.w));
}
}else{
if(Y==0) swap(X,Y);
//X==0
if(Y==m1.u || Y==m2.u || Y==m3.u){
return m3.w;
}else{
return max(g[Y][0].w,m2.w);
}
}
}
int subtask1(int X,int Y){
if(cycle) return ma;
else return -1;
}
int getMinimumFuelCapacity(int X, int Y) {
//min path ที่มี node อยู่ระหว่าง path
//หา min ถนนที่เชื่อมกับโหนดตรงกลาง
//เทียบ min กับ path อื่นๆ ไปได้ (เชื่อมตรงเลยก็ได้)
if(sub2) return subtask2(X,Y);
else if(sub1) return subtask1(X,Y);
return 0;
}
Compilation message
swap.cpp: In function 'int subtask2(int, int)':
swap.cpp:60:1: warning: control reaches end of non-void function [-Wreturn-type]
60 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
3 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2656 KB |
Output is correct |
7 |
Correct |
3 ms |
2652 KB |
Output is correct |
8 |
Correct |
3 ms |
2636 KB |
Output is correct |
9 |
Correct |
43 ms |
8024 KB |
Output is correct |
10 |
Correct |
75 ms |
9028 KB |
Output is correct |
11 |
Correct |
53 ms |
8892 KB |
Output is correct |
12 |
Correct |
62 ms |
9312 KB |
Output is correct |
13 |
Correct |
58 ms |
9244 KB |
Output is correct |
14 |
Correct |
71 ms |
8152 KB |
Output is correct |
15 |
Correct |
120 ms |
10808 KB |
Output is correct |
16 |
Correct |
117 ms |
10720 KB |
Output is correct |
17 |
Correct |
138 ms |
11020 KB |
Output is correct |
18 |
Correct |
114 ms |
11320 KB |
Output is correct |
19 |
Correct |
67 ms |
8444 KB |
Output is correct |
20 |
Correct |
116 ms |
12408 KB |
Output is correct |
21 |
Correct |
116 ms |
12112 KB |
Output is correct |
22 |
Correct |
125 ms |
12332 KB |
Output is correct |
23 |
Correct |
156 ms |
12436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
115 ms |
12720 KB |
Output is correct |
4 |
Correct |
117 ms |
12764 KB |
Output is correct |
5 |
Correct |
139 ms |
13020 KB |
Output is correct |
6 |
Correct |
117 ms |
12880 KB |
Output is correct |
7 |
Correct |
124 ms |
12984 KB |
Output is correct |
8 |
Correct |
146 ms |
12700 KB |
Output is correct |
9 |
Correct |
113 ms |
12808 KB |
Output is correct |
10 |
Correct |
118 ms |
12828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
3 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2656 KB |
Output is correct |
7 |
Correct |
3 ms |
2652 KB |
Output is correct |
8 |
Correct |
3 ms |
2636 KB |
Output is correct |
9 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
3 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2656 KB |
Output is correct |
7 |
Correct |
3 ms |
2652 KB |
Output is correct |
8 |
Correct |
3 ms |
2636 KB |
Output is correct |
9 |
Correct |
43 ms |
8024 KB |
Output is correct |
10 |
Correct |
75 ms |
9028 KB |
Output is correct |
11 |
Correct |
53 ms |
8892 KB |
Output is correct |
12 |
Correct |
62 ms |
9312 KB |
Output is correct |
13 |
Correct |
58 ms |
9244 KB |
Output is correct |
14 |
Correct |
71 ms |
8152 KB |
Output is correct |
15 |
Correct |
120 ms |
10808 KB |
Output is correct |
16 |
Correct |
117 ms |
10720 KB |
Output is correct |
17 |
Correct |
138 ms |
11020 KB |
Output is correct |
18 |
Correct |
114 ms |
11320 KB |
Output is correct |
19 |
Correct |
115 ms |
12720 KB |
Output is correct |
20 |
Correct |
117 ms |
12764 KB |
Output is correct |
21 |
Correct |
139 ms |
13020 KB |
Output is correct |
22 |
Correct |
117 ms |
12880 KB |
Output is correct |
23 |
Correct |
124 ms |
12984 KB |
Output is correct |
24 |
Correct |
146 ms |
12700 KB |
Output is correct |
25 |
Correct |
113 ms |
12808 KB |
Output is correct |
26 |
Correct |
118 ms |
12828 KB |
Output is correct |
27 |
Incorrect |
3 ms |
2636 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |