QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#867460 | #3855. Regional development | 654321 | WA | 0ms | 15956kb | C++14 | 4.4kb | 2025-01-23 16:43:58 | 2025-01-23 16:44:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define Re char y_y
#define rint register int
#define tam cerr << 1e3 * clock ( ) / CLOCKS_PER_SEC << 'm' << 's' << ' ' << ( &y_y - &x_x ) / 1024.0 / 1024.0 << 'M' << 'B' << '\n' , 0
char x_x;
const int N = 2e5 + 5;
char buf[ 1 << 23 ] , *p1 = buf , *p2 = buf , obuf[ 1 << 23 ] , *p3 = obuf;
#define getchar( ) ( p1 == p2 && ( p2 = ( p1 = buf ) + fread( buf , 1 , 1 << 23 , stdin ) , p1 == p2 ) ? EOF : *p1 ++ )
#define putchar( x ) ( p3 - obuf < 1 << 23 ) ? ( *p3 ++ = x ) : ( fwrite ( obuf , p3 - obuf , 1 , stdout ) , p3 = obuf , * p3 ++ = x )
template < class T >
inline void read ( T & s )
{
s = 0;
bool q = false;
char c = getchar ();
while ( ! isdigit ( c ) ) { if (c == '-') q = true; c = getchar (); }
while (isdigit (c) ) { s = (s << 1) + (s << 3) + (c ^ 48); c = getchar (); }
if (q) s = -s;
}
template < class T , class ...Args >
inline void read ( T &s , Args &...x ) { read ( s ) , read ( x... ); }
#define pc putchar
stack < char > so;
template <class S>
inline void print ( S x )
{
if ( x == 0 ) return pc ( '0' ) , pc ( ' ' ) , void ();
if ( x < 0 ) x = - x , pc ( '-' );
while ( x ) { so. push ( x % 10 + 48 ) , x /= 10; }
while ( ! so. empty () ) pc ( so. top () ) , so. pop ();
putchar ( ' ' );
}
template <class S , class ...Args>
inline void print ( S x , Args ...y ) { print ( x ) , print ( y ... ); }
#undef pc
inline void flush ( ) { fwrite ( obuf , p3 - obuf , 1 , stdout ) , p3 = obuf; }
#define endl putchar ( '\n' )
namespace Dinic
{
const int inf = 1e9;
int n , head[ N ] , nxt[ N ] , w[ N ] , d[ N ] , to[ N ] , tot = 1 , S , T , head2[ N ];
int id[ N ]; int be[ N ];
void add ( int x , int y , int f , int o = 1 )
{
++ tot; be[ tot ] = x;
nxt[ tot ] = head[ x ]; head[ x ] = tot;
w[ tot ] = f , to[ tot ] = y;
if ( o ) add ( y , x , 0 , 0 );
}
bool bfs ( )
{
for ( rint i = 1 ; i <= n ; i ++ )
d[ i ] = 0;
d[ S ] = 1;
queue < int > q;
q. push ( S );
while ( ! q. empty () )
{
int x = q. front (); q. pop ();
for ( rint i = head[ x ] ; i ; i = nxt[ i ] )
{
int y = to[ i ] , f = w[ i ];
if ( d[ y ] || ! f ) continue;
d[ y ] = d[ x ] + 1 , q. push ( y );
if ( y == T ) return 1;
}
}
return 0;
}
int dinic ( int x , int rem )
{
if ( x == T ) return rem;
int rev = rem;
for ( rint &i = head2[ x ] ; i ; i = nxt[ i ] )
{
int y = to[ i ] , f = w[ i ];
if ( d[ y ] != d[ x ] + 1 || ! f ) continue;
int k = dinic ( y , min ( f , rev ) );
if ( ! k ) d[ y ] = 0;
else w[ i ] -= k , w[ i ^ 1 ] += k;
rev -= k;
if ( ! rev ) break;
}
return rem - rev;
}
int main ()
{
int res = 0;
while ( bfs () )
{
for ( rint i = 1 ; i <= n ; i ++ ) head2[ i ] = head[ i ];
int cre = 0;
while ( cre = dinic ( S , inf ) )
res += cre;
}
return res;
}
void init ()
{
S = T = n = 0 , tot = 1;
for ( rint i = 1 ; i <= n ; i ++ )
head[ i ] = 0;
}
}
int n , m , L , a[ N ];
struct line { int x , y , w; } g[ N ];
int z[ N ]; int ans[ N ]; int h[ N ];
map < pair < int , int > , int > mp;
signed main ()
{
read ( n , m , L ); int & cnt = Dinic :: n;
for ( rint i = 1 ; i <= n ; i ++ )
z[ i ] = ++ cnt;
Dinic :: S = ++ cnt;
Dinic :: T = ++ cnt;
for ( rint i = 1 ; i <= m ; i ++ )
read ( g[ i ]. x , g[ i ]. y , g[ i ]. w ) , ans[ i ] = g[ i ]. w , a[ g[ i ]. x ] -= g[ i ]. w , a[ g[ i ]. x ] += g[ i ]. w;
for ( rint i = 1 ; i <= n ; i ++ )
{
a[ i ] /= L;
if ( a[ i ] < 0 )
Dinic :: add ( z[ i ] , Dinic :: T , - a[ i ] );
else if ( a[ i ] > 0 )
Dinic :: add ( Dinic :: S , z[ i ] , a[ i ] );
}
int l = Dinic :: tot + 1;
for ( rint i = 1 ; i <= m ; i ++ )
Dinic :: add ( g[ i ]. y , g[ i ]. x , 1 ),
mp[ { min ( g[ i ]. y , g[ i ]. x ) , max ( g[ i ]. y , g[ i ]. x ) } ] = i;
int r = Dinic :: tot;
Dinic :: main ();
for ( rint i = l ; i <= r ; i ++ ) if ( Dinic :: w[ i ] )
{
int z = mp[ { min ( Dinic :: be[ i ] , Dinic :: to[ i ] ) , max ( Dinic :: be[ i ] , Dinic :: to[ i ] ) } ];
ans[ z ] -= L;
}
for ( rint i = 1 ; i <= m ; i ++ )
print ( ans[ i ] ) , endl;
return flush ( ) , 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 15956kb
input:
10 23 3 2 10 1 2 6 1 6 9 1 7 9 1 6 7 1 3 6 1 1 3 1 1 6 2 6 10 1 2 9 1 4 9 2 4 7 2 3 10 2 3 9 1 6 8 1 7 8 2 3 5 1 5 9 1 8 9 2 3 8 2 1 5 2 1 4 1 5 10 2
output:
-2 -2 -2 -2 -2 -2 -2 -1 -2 -2 -1 -1 -1 -2 -2 -1 -2 -2 -1 -1 -1 -2 -1
result:
wrong answer wrong plan