#include<bits/stdc++.h>
using namespace std ;
#define maxn 250009
#define ll long long
#define pb push_back
#define fi first
#define se second
#define left id<<1
#define right id<<1|1
#define re exit(0);
#define _lower(x) lower_bound(v.begin(),v.end(),x)-v.begin()+1
#define TIME (1.0*clock()/CLOCK_PERS_SEC)
const int mod = 1e9+7 ;
const int INF = 1e9 ;
typedef vector<int> vi ;
typedef pair<int,int> pii ;
typedef vector<pii> vii ;
void add ( int &a , int b )
{
a += b ;
if ( a >= mod ) a -= mod ;
if ( a < 0 ) a += mod ;
}
template < typename T > void chkmin ( T &a , T b ) { if ( a > b ) a = b ;}
template < typename T > void chkmax ( T &a , T b ) { if ( a < b ) a = b ;}
void rf ()
{
freopen("bai1.inp","r",stdin) ;
}
int _pow ( int a , int n )
{
if ( n == 0 ) return 1 ;
int res = _pow (a,n/2) ;
if ( n % 2 ) return 1ll*res*res%mod*a%mod ;
else return 1ll*res*res%mod ;
}
mt19937 rng(time(0)) ;
//#include "grader.h"
int n , m ;
vi u , v , w ;
int lab [maxn] , deg [maxn] ;
struct shape {
int u , v , w ;
}e[maxn];
bool cmp ( shape u , shape v )
{
return u.w < v.w ;
}
void init ( int N , int M , vi U , vi V , vi W )
{
n = N , m = M ;
for ( int i = 0 ; i < m ; i ++ )
{
U [i] ++ , V [i] ++ ;
e [i+1] = {U[i],V[i],W[i]} ;
}
sort (e+1,e+m+1,cmp) ;
}
int find ( int u )
{
return (lab[u]<0?u:lab[u]=find(lab[u])) ;
}
void uni ( int u , int v )
{
if ((u=find(u)) == (v=find(v))) return ;
if ( lab [u] > lab [v] ) swap (u,v) ;
lab [u] += lab [v] ;
lab [v] = u ;
}
int getMinimumFuelCapacity ( int x , int y )
{
x ++ , y ++ ;
int l = 1 , r = m ;
int res = -1 ;
while ( l <= r )
{
for ( int i = 1 ; i <= n ; i ++ ) lab [i] = -1 , deg [i] = 0 ;
int mid = (l+r)/2 ;
bool ok = false ;
for ( int i = 1 ; i <= mid ; i ++ )
{
if (find(e[i].u) == find(e[i].v) && find(e[i].u) == find(x) && find(e[i].u) == find(y)) ok = true ;
deg [e[i].u] ++ , deg [e[i].v] ++ ;
uni (e[i].u,e[i].v) ;
}
for ( int i = 1 ; i <= n ; i ++ )
{
if ( deg [i] >= 3 && find (i) == find (x) && find (i) == find (y) ) ok = true ;
}
if ( ok == true ) res = e[mid].w , r = mid-1 ;
else l = mid+1 ;
}
return res ;
}
//int main ()
//{
// init(5, 6, {0, 0, 1, 1, 1, 2}, {1, 2, 2, 3, 4, 3}, {4, 4, 1, 2, 10, 3});
// cout << getMinimumFuelCapacity(1,2) ;
//}
Compilation message
swap.cpp: In function 'void rf()':
swap.cpp:33:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen("bai1.inp","r",stdin) ;
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
67 ms |
5560 KB |
Output is correct |
10 |
Correct |
147 ms |
5612 KB |
Output is correct |
11 |
Correct |
163 ms |
5624 KB |
Output is correct |
12 |
Correct |
172 ms |
5916 KB |
Output is correct |
13 |
Correct |
126 ms |
5828 KB |
Output is correct |
14 |
Execution timed out |
2068 ms |
5824 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Execution timed out |
2043 ms |
7928 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2512 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
2 ms |
2392 KB |
Output is correct |
25 |
Correct |
2 ms |
2396 KB |
Output is correct |
26 |
Correct |
2 ms |
2600 KB |
Output is correct |
27 |
Correct |
1 ms |
2500 KB |
Output is correct |
28 |
Correct |
2 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
67 ms |
5560 KB |
Output is correct |
11 |
Correct |
147 ms |
5612 KB |
Output is correct |
12 |
Correct |
163 ms |
5624 KB |
Output is correct |
13 |
Correct |
172 ms |
5916 KB |
Output is correct |
14 |
Correct |
126 ms |
5828 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2512 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2392 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
2 ms |
2392 KB |
Output is correct |
30 |
Correct |
2 ms |
2396 KB |
Output is correct |
31 |
Correct |
2 ms |
2600 KB |
Output is correct |
32 |
Correct |
1 ms |
2500 KB |
Output is correct |
33 |
Correct |
2 ms |
2396 KB |
Output is correct |
34 |
Correct |
8 ms |
3132 KB |
Output is correct |
35 |
Correct |
170 ms |
7732 KB |
Output is correct |
36 |
Correct |
168 ms |
7980 KB |
Output is correct |
37 |
Correct |
167 ms |
7720 KB |
Output is correct |
38 |
Correct |
157 ms |
7632 KB |
Output is correct |
39 |
Correct |
160 ms |
7632 KB |
Output is correct |
40 |
Correct |
172 ms |
7216 KB |
Output is correct |
41 |
Correct |
168 ms |
8028 KB |
Output is correct |
42 |
Correct |
172 ms |
7604 KB |
Output is correct |
43 |
Correct |
96 ms |
7748 KB |
Output is correct |
44 |
Correct |
202 ms |
7972 KB |
Output is correct |
45 |
Correct |
204 ms |
9308 KB |
Output is correct |
46 |
Correct |
173 ms |
7744 KB |
Output is correct |
47 |
Correct |
158 ms |
7600 KB |
Output is correct |
48 |
Correct |
153 ms |
7984 KB |
Output is correct |
49 |
Correct |
57 ms |
9336 KB |
Output is correct |
50 |
Correct |
61 ms |
8392 KB |
Output is correct |
51 |
Correct |
139 ms |
8812 KB |
Output is correct |
52 |
Correct |
206 ms |
10028 KB |
Output is correct |
53 |
Correct |
200 ms |
10844 KB |
Output is correct |
54 |
Correct |
202 ms |
13140 KB |
Output is correct |
55 |
Correct |
116 ms |
7708 KB |
Output is correct |
56 |
Correct |
300 ms |
10608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
67 ms |
5560 KB |
Output is correct |
10 |
Correct |
147 ms |
5612 KB |
Output is correct |
11 |
Correct |
163 ms |
5624 KB |
Output is correct |
12 |
Correct |
172 ms |
5916 KB |
Output is correct |
13 |
Correct |
126 ms |
5828 KB |
Output is correct |
14 |
Execution timed out |
2068 ms |
5824 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
67 ms |
5560 KB |
Output is correct |
11 |
Correct |
147 ms |
5612 KB |
Output is correct |
12 |
Correct |
163 ms |
5624 KB |
Output is correct |
13 |
Correct |
172 ms |
5916 KB |
Output is correct |
14 |
Correct |
126 ms |
5828 KB |
Output is correct |
15 |
Execution timed out |
2068 ms |
5824 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |