Submission #395248

# Submission time Handle Problem Language Result Execution time Memory
395248 2021-04-28T04:05:55 Z irmuun Swapping Cities (APIO20_swap) C++17
43 / 100
2000 ms 7748 KB
#include "swap.h"
#include<bits/stdc++.h>
using namespace std;
int a,b,i,n,m,link[200000],edge[200000],sz[200000],x,y,ans[200000],edgeNum[200000],d,e;
pair<int, pair<int,int> >p[200000];
int find(int x){
  if(link[x]==x){
    return x;
  }
  return link[x]=find(link[x]);
}
bool same(int a,int b){
  if(find(a)==find(b)){
    return true;
  }
  else{
    return false;
  }
}
void unite(int a,int b){
  a=find(a);
  b=find(b);
  if(sz[a]<sz[b]){
    swap(a,b);
  }
  if(ans[b]==1){
    ans[a]=1;
  }
  link[b]=a;
  sz[a]+=sz[b];
}
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
  m=M;
  n=N;
  for(i=0;i<n;i++){
    edgeNum[i]=0;
  }
  for(i=0;i<m;i++){
    p[i].first=W[i];
    p[i].second.first=U[i];
    p[i].second.second=V[i];
    edgeNum[U[i]]++;
    edgeNum[V[i]]++;
  }
  sort(p,p+m);
  sort(edgeNum,edgeNum+n);
}
int getMinimumFuelCapacity(int X, int Y) {
  if((edgeNum[1]==1&&edgeNum[n-1]==2)||n==2){
    return -1;
  }
  if(edgeNum[0]==edgeNum[n-1]&&edgeNum[0]==2){
    return p[m-1].first;
  }
  if(edgeNum[n-2]==1&&edgeNum[n-1]==n-1){
    d=0;
    e=0;
    for(i=0;i<m;i++){
      if(p[i].second.second==X){
        d=p[i].first;
      }
      if(p[i].second.second==Y){
        e=p[i].first;
      }
    }
    return max(p[2].first,max(d,e));
  }
  for(i=0;i<n;i++){
    link[i]=i;
    sz[i]=1;
    edge[i]=0;
    ans[i]=0;
  }
  for(i=0;i<m;i++){
    x=p[i].second.first;
    y=p[i].second.second;
    edge[x]++;
    edge[y]++;
    if(find(x)==find(y)||edge[x]>2||edge[y]>2){
      ans[find(x)]=1;
      ans[find(y)]=1;
    }
    unite(x,y);
    if(find(X)==find(Y)&&ans[find(X)]==1){
      return p[i].first;
    }
  }
  return -1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 34 ms 3388 KB Output is correct
10 Correct 42 ms 4036 KB Output is correct
11 Correct 42 ms 3984 KB Output is correct
12 Correct 46 ms 4176 KB Output is correct
13 Correct 44 ms 4224 KB Output is correct
14 Correct 40 ms 3404 KB Output is correct
15 Correct 106 ms 5824 KB Output is correct
16 Correct 108 ms 5716 KB Output is correct
17 Correct 112 ms 5932 KB Output is correct
18 Correct 107 ms 5964 KB Output is correct
19 Correct 61 ms 4236 KB Output is correct
20 Correct 107 ms 6952 KB Output is correct
21 Correct 109 ms 7212 KB Output is correct
22 Correct 114 ms 7336 KB Output is correct
23 Correct 112 ms 7368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Execution timed out 2092 ms 5476 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 34 ms 3388 KB Output is correct
11 Correct 42 ms 4036 KB Output is correct
12 Correct 42 ms 3984 KB Output is correct
13 Correct 46 ms 4176 KB Output is correct
14 Correct 44 ms 4224 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 336 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 7 ms 940 KB Output is correct
35 Correct 69 ms 4532 KB Output is correct
36 Correct 74 ms 4532 KB Output is correct
37 Correct 68 ms 4580 KB Output is correct
38 Correct 67 ms 4536 KB Output is correct
39 Correct 71 ms 4548 KB Output is correct
40 Correct 66 ms 4320 KB Output is correct
41 Correct 70 ms 4588 KB Output is correct
42 Correct 68 ms 4636 KB Output is correct
43 Correct 56 ms 4660 KB Output is correct
44 Correct 75 ms 4536 KB Output is correct
45 Correct 95 ms 5756 KB Output is correct
46 Correct 71 ms 4532 KB Output is correct
47 Correct 68 ms 4532 KB Output is correct
48 Correct 73 ms 4832 KB Output is correct
49 Correct 64 ms 5884 KB Output is correct
50 Correct 51 ms 4552 KB Output is correct
51 Correct 75 ms 5024 KB Output is correct
52 Correct 101 ms 6308 KB Output is correct
53 Correct 102 ms 6884 KB Output is correct
54 Correct 117 ms 7748 KB Output is correct
55 Correct 62 ms 4628 KB Output is correct
56 Correct 120 ms 6680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 34 ms 3388 KB Output is correct
10 Correct 42 ms 4036 KB Output is correct
11 Correct 42 ms 3984 KB Output is correct
12 Correct 46 ms 4176 KB Output is correct
13 Correct 44 ms 4224 KB Output is correct
14 Correct 40 ms 3404 KB Output is correct
15 Correct 106 ms 5824 KB Output is correct
16 Correct 108 ms 5716 KB Output is correct
17 Correct 112 ms 5932 KB Output is correct
18 Correct 107 ms 5964 KB Output is correct
19 Execution timed out 2092 ms 5476 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 34 ms 3388 KB Output is correct
11 Correct 42 ms 4036 KB Output is correct
12 Correct 42 ms 3984 KB Output is correct
13 Correct 46 ms 4176 KB Output is correct
14 Correct 44 ms 4224 KB Output is correct
15 Correct 40 ms 3404 KB Output is correct
16 Correct 106 ms 5824 KB Output is correct
17 Correct 108 ms 5716 KB Output is correct
18 Correct 112 ms 5932 KB Output is correct
19 Correct 107 ms 5964 KB Output is correct
20 Execution timed out 2092 ms 5476 KB Time limit exceeded
21 Halted 0 ms 0 KB -