#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 ++ ;
for ( int i = 1 ; i <= n ; i ++ ) lab [i] = -1 , deg [i] = 0 ;
for ( int i = 1 ; i <= m ; i ++ )
{
int u = e[i].u , v = e[i].v , w = e[i].w ;
if ( find (u) == find (v) && find (u) == find (x) && find (u) == find (y) ) return w ;
uni (u,v) ;
deg [u] ++ , deg [v] ++ ;
if ( deg [u] >= 3 && find (u) == find (x) && find (u) == find (y) ) return w ;
if ( deg [v] >= 3 && find (v) == find (x) && find (v) == find (y) ) return w ;
}
return -1 ;
}
//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 |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2408 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
30 ms |
5568 KB |
Output is correct |
10 |
Correct |
37 ms |
5608 KB |
Output is correct |
11 |
Correct |
39 ms |
5620 KB |
Output is correct |
12 |
Correct |
42 ms |
5820 KB |
Output is correct |
13 |
Correct |
37 ms |
5816 KB |
Output is correct |
14 |
Execution timed out |
2060 ms |
5828 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Execution timed out |
2060 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 |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2408 KB |
Output is correct |
8 |
Correct |
1 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 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
12 |
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 |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 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 |
2408 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
30 ms |
5568 KB |
Output is correct |
11 |
Correct |
37 ms |
5608 KB |
Output is correct |
12 |
Correct |
39 ms |
5620 KB |
Output is correct |
13 |
Correct |
42 ms |
5820 KB |
Output is correct |
14 |
Correct |
37 ms |
5816 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2408 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
30 ms |
5568 KB |
Output is correct |
10 |
Correct |
37 ms |
5608 KB |
Output is correct |
11 |
Correct |
39 ms |
5620 KB |
Output is correct |
12 |
Correct |
42 ms |
5820 KB |
Output is correct |
13 |
Correct |
37 ms |
5816 KB |
Output is correct |
14 |
Execution timed out |
2060 ms |
5828 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 |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 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 |
2408 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
30 ms |
5568 KB |
Output is correct |
11 |
Correct |
37 ms |
5608 KB |
Output is correct |
12 |
Correct |
39 ms |
5620 KB |
Output is correct |
13 |
Correct |
42 ms |
5820 KB |
Output is correct |
14 |
Correct |
37 ms |
5816 KB |
Output is correct |
15 |
Execution timed out |
2060 ms |
5828 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |