#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
#ifndef EVAL
#include "grader.cpp"
#endif
struct DSU{
vector<int> p;
vector<int> mx;
DSU(int n) : p(n),mx(n){
for(int i=0;i<n;i++){
p[i]=i;
mx[i]=0;
}
}
int find(int x){
if(p[x]==x){
return x;
}
else{
return p[x]=find(p[x]);
}
}
void merge(int x,int y,int val){
int a=find(x),b=find(y);
if(a==b){
mx[a]=max(val,mx[a]);
return;
}
else{
mx[b]=max(mx[b],mx[a]);
p[a]=b;
mx[b]=max(mx[b],val);
return;
}
}
};
vector<int> e[100005];
int used[100005],ans[100005];
DSU dsu(100005);
bool h=0;
void dfs(int x){
used[x]++;
if(e[x].size()<2){
h=1;
return;
}
if(h==1){
return;
}
for(auto w : e[x]){
if(used[w]==0){
dfs(w);
}
}
}
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W){
for(int i=0;i<M;i++){
e[U[i]].push_back(V[i]);
e[V[i]].push_back(U[i]);
dsu.merge(U[i],V[i],W[i]);
}
for(int i=0;i<N;i++){
if(used[i]==0){
h=0;
dfs(i);
if(h==1){
ans[dsu.find(i)]=-1;
}
else{
ans[dsu.find(i)]=1;
}
}
}
}
int getMinimumFuelCapacity(int X, int Y) {
if(dsu.find(X)!=dsu.find(Y) || ans[dsu.find(X)]==-1){
return -1;
}
else{
return dsu.mx[dsu.find(X)];
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
3 ms |
3412 KB |
Output is correct |
6 |
Incorrect |
2 ms |
3412 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Incorrect |
90 ms |
11836 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
3 ms |
3412 KB |
Output is correct |
6 |
Incorrect |
2 ms |
3412 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
3 ms |
3412 KB |
Output is correct |
6 |
Incorrect |
2 ms |
3412 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
3 ms |
3412 KB |
Output is correct |
6 |
Incorrect |
2 ms |
3412 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
3 ms |
3412 KB |
Output is correct |
6 |
Incorrect |
2 ms |
3412 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |