QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#867470#3855. Regional development654321AC ✓4ms16588kbC++204.4kb2025-01-23 16:51:512025-01-23 16:51:51

Judging History

你现在查看的是最新测评结果

  • [2025-01-23 16:51:51]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:16588kb
  • [2025-01-23 16:51:51]
  • 提交

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 ]. y ] += 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;
  cerr << Dinic :: main () << '\n';
  for ( rint i = l ; i <= r ; i += 2 ) 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: 100
Accepted
time: 0ms
memory: 15948kb

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 
1 
1 
1 
1 
1 
-2 
2 
1 
1 
-1 
2 
-1 
-2 
1 
2 
1 
-2 
2 
-1 
-1 
1 
2 

result:

ok correct plan

Test #2:

score: 0
Accepted
time: 1ms
memory: 15948kb

input:

100 1297 11
27 34 5
7 34 6
7 90 3
80 90 6
37 80 6
37 48 5
47 48 6
47 86 5
56 86 6
56 84 5
63 84 6
38 63 6
66 91 8
12 91 6
12 15 5
15 22 1
22 87 5
46 87 6
46 63 10
63 87 8
71 87 6
65 71 6
38 65 1
38 67 4
29 67 6
9 29 6
9 21 5
16 21 6
16 89 2
89 98 5
4 98 6
4 13 4
13 33 5
14 33 6
14 66 10
66 86 10
57 ...

output:

5 
6 
-8 
6 
6 
5 
6 
5 
6 
5 
6 
6 
8 
6 
5 
1 
-6 
-5 
10 
8 
6 
6 
1 
4 
6 
6 
5 
6 
-9 
5 
-5 
4 
5 
6 
-1 
10 
6 
6 
5 
7 
6 
6 
8 
5 
6 
5 
5 
6 
6 
5 
6 
5 
6 
1 
6 
3 
5 
6 
5 
5 
6 
8 
9 
6 
8 
5 
6 
5 
-6 
-5 
6 
5 
6 
6 
5 
6 
5 
6 
6 
5 
6 
5 
10 
6 
7 
5 
5 
-5 
7 
5 
5 
6 
-5 
5 
5 
6 ...

result:

ok correct plan

Test #3:

score: 0
Accepted
time: 1ms
memory: 15904kb

input:

100 1272 18
39 40 14
39 95 4
21 95 14
12 21 14
12 82 16
28 82 14
17 28 14
17 67 5
35 67 14
11 35 1
11 67 15
17 58 4
58 80 4
28 80 14
28 77 3
25 77 10
22 25 14
22 54 4
13 54 14
13 99 4
86 99 14
86 89 16
21 89 14
21 62 4
16 62 14
16 81 4
76 81 14
56 76 1
28 56 14
28 47 4
19 47 14
19 91 4
22 91 14
13 2...

output:

14 
4 
14 
14 
-2 
14 
14 
5 
14 
1 
-3 
4 
4 
-4 
3 
10 
14 
4 
14 
-14 
14 
16 
14 
4 
14 
-14 
14 
1 
14 
4 
14 
-14 
-4 
14 
-14 
4 
14 
14 
-14 
4 
13 
4 
2 
-4 
4 
4 
14 
4 
17 
14 
4 
4 
-4 
9 
-4 
4 
14 
14 
17 
4 
4 
14 
4 
4 
4 
14 
14 
4 
4 
14 
14 
-14 
2 
4 
9 
4 
4 
-4 
10 
4 
4 
-4 
-...

result:

ok correct plan

Test #4:

score: 0
Accepted
time: 1ms
memory: 16088kb

input:

100 1350 3
22 75 2
22 50 2
22 35 1
25 35 2
42 76 2
39 42 2
36 39 2
14 36 2
14 33 1
33 72 1
54 72 2
54 73 1
5 73 2
45 92 2
23 92 2
23 26 2
26 62 1
6 62 1
22 86 1
24 86 2
7 24 2
7 55 2
20 39 2
20 73 1
27 73 2
27 68 1
24 68 2
24 98 1
8 98 2
8 33 1
3 33 2
1 3 1
3 97 1
83 97 2
83 90 1
38 90 2
38 86 1
21 ...

output:

-1 
2 
1 
2 
2 
2 
2 
2 
1 
1 
2 
1 
-1 
-1 
-1 
2 
1 
-2 
1 
2 
2 
2 
2 
-2 
-1 
1 
2 
1 
2 
1 
2 
1 
1 
2 
1 
-1 
1 
1 
2 
2 
1 
1 
2 
1 
1 
1 
2 
1 
2 
2 
1 
2 
2 
1 
2 
1 
1 
1 
2 
2 
1 
1 
2 
1 
2 
-2 
2 
-1 
1 
-2 
2 
2 
-2 
2 
1 
2 
1 
2 
2 
2 
2 
-2 
-1 
2 
-2 
1 
2 
1 
1 
-1 
1 
1 
2 
-2 
2...

result:

ok correct plan

Test #5:

score: 0
Accepted
time: 2ms
memory: 16588kb

input:

1000 9780 26
39 260 1
215 260 25
215 483 1
483 801 1
801 977 1
379 977 25
316 379 25
316 732 1
474 732 25
183 474 25
177 183 25
177 788 1
525 788 25
525 909 1
51 909 25
51 565 1
203 565 25
203 353 1
353 655 8
655 814 1
814 999 1
305 999 25
52 305 25
52 978 20
839 978 25
646 839 25
536 646 25
536 571...

output:

1 
25 
1 
1 
1 
25 
25 
1 
25 
25 
25 
-25 
25 
1 
-1 
-25 
25 
1 
8 
1 
1 
25 
25 
-6 
25 
25 
25 
1 
25 
1 
25 
1 
25 
1 
25 
-1 
1 
13 
25 
1 
1 
25 
25 
25 
1 
1 
1 
25 
1 
-1 
1 
1 
25 
-25 
-1 
1 
25 
25 
1 
25 
1 
25 
25 
1 
-25 
25 
1 
25 
1 
25 
-25 
25 
25 
25 
1 
-25 
25 
1 
25 
1 
-1 
1 ...

result:

ok correct plan

Test #6:

score: 0
Accepted
time: 0ms
memory: 15956kb

input:

20 190 20
2 7 10
4 7 18
4 19 15
1 19 14
1 2 13
1 13 10
3 13 10
1 3 12
8 10 19
10 12 13
12 16 12
8 16 9
3 19 18
2 19 5
2 17 15
4 17 2
4 5 3
1 5 8
14 19 16
4 14 15
19 20 7
13 20 11
3 20 8
7 9 14
9 13 16
13 16 14
1 16 19
1 14 14
8 14 1
3 8 3
3 9 8
9 17 1
17 19 10
1 20 1
10 20 17
4 10 5
4 6 14
6 19 16
1...

output:

10 
18 
-5 
-6 
13 
-10 
-10 
12 
19 
13 
12 
9 
-2 
-15 
15 
2 
3 
8 
16 
-5 
7 
11 
8 
14 
16 
14 
-1 
-6 
1 
3 
8 
1 
10 
-19 
-3 
5 
14 
-4 
13 
17 
4 
9 
7 
13 
10 
2 
8 
-13 
-12 
1 
5 
17 
-4 
2 
16 
13 
17 
15 
11 
16 
17 
-11 
17 
14 
-5 
1 
3 
3 
-6 
6 
-8 
2 
-2 
-13 
19 
-19 
-8 
-5 
10 ...

result:

ok correct plan

Test #7:

score: 0
Accepted
time: 4ms
memory: 16388kb

input:

300 9997 94
3 81 59
80 81 43
40 80 43
40 121 51
121 151 51
95 151 47
95 158 59
149 158 43
149 258 51
99 258 43
99 150 51
150 299 51
29 299 43
29 151 5
151 289 51
13 289 43
13 226 51
182 226 30
182 248 51
6 248 17
6 243 51
91 243 43
91 193 51
169 193 43
169 287 51
237 287 43
153 237 31
153 289 51
155...

output:

59 
43 
43 
51 
51 
47 
59 
43 
51 
-51 
51 
-43 
-51 
5 
51 
43 
-43 
30 
51 
17 
-43 
-51 
51 
43 
51 
43 
31 
51 
43 
51 
43 
43 
-43 
43 
86 
51 
43 
51 
43 
43 
-71 
51 
43 
51 
51 
43 
43 
-43 
-65 
51 
43 
-43 
43 
51 
51 
43 
51 
43 
51 
43 
-43 
43 
51 
51 
51 
43 
51 
43 
43 
51 
51 
43 
4...

result:

ok correct plan

Test #8:

score: 0
Accepted
time: 2ms
memory: 16332kb

input:

100 4950 497
11 84 473
37 84 457
37 44 399
7 44 434
7 97 276
11 97 299
42 75 227
75 96 345
10 96 6
10 64 345
64 91 15
16 91 390
3 16 431
3 8 449
2 8 129
2 83 360
83 86 430
22 86 377
22 26 354
8 26 30
8 60 386
60 69 473
35 69 181
18 35 161
18 40 246
12 40 100
12 18 224
18 57 312
55 57 253
55 97 417
6...

output:

-24 
457 
399 
434 
-221 
-198 
227 
345 
6 
345 
15 
390 
431 
449 
129 
360 
430 
-120 
354 
30 
386 
473 
181 
161 
246 
100 
224 
312 
253 
417 
473 
418 
51 
18 
-180 
-255 
456 
214 
488 
15 
432 
413 
300 
-179 
264 
169 
-286 
99 
440 
477 
170 
220 
90 
-30 
375 
126 
74 
-183 
63 
-49 
157...

result:

ok correct plan

Test #9:

score: 0
Accepted
time: 4ms
memory: 16464kb

input:

1000 10000 2
403 261 1
423 168 1
977 444 1
298 748 1
77 687 1
229 276 1
791 650 1
39 507 1
747 612 1
882 369 1
376 1000 1
812 953 1
713 123 1
403 749 1
215 394 1
342 218 1
691 673 1
33 289 1
437 652 1
217 223 1
247 665 1
701 192 1
229 726 1
18 850 1
585 343 1
407 925 1
940 382 1
920 851 1
901 740 1
...

output:

1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
-1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
-1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1...

result:

ok correct plan

Test #10:

score: 0
Accepted
time: 2ms
memory: 16092kb

input:

1000 1935 4
860 820 1
102 103 1
910 911 1
230 190 1
234 235 3
151 150 1
506 507 1
528 568 1
273 313 1
149 150 1
798 758 1
597 557 1
610 650 1
746 747 1
63 23 3
102 142 3
619 620 1
81 41 3
238 278 1
760 759 1
799 798 1
853 852 1
193 194 3
199 239 1
150 190 1
876 916 1
996 997 2
244 243 1
282 242 1
27...

output:

1 
1 
1 
1 
3 
1 
1 
1 
-3 
1 
1 
-3 
-3 
1 
-1 
3 
-3 
-1 
1 
1 
1 
1 
-1 
1 
1 
-3 
2 
1 
1 
-3 
-3 
1 
-3 
1 
-3 
1 
1 
-3 
-3 
1 
1 
1 
1 
1 
1 
-3 
-3 
3 
1 
3 
1 
1 
-1 
1 
1 
1 
1 
-1 
-1 
1 
-1 
1 
3 
1 
1 
1 
1 
1 
1 
3 
1 
1 
1 
3 
1 
-1 
-1 
-1 
1 
1 
1 
1 
3 
1 
1 
-1 
3 
1 
1 
-1 
-3 
-...

result:

ok correct plan