QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#98664#6329. Colorful GraphCSU2023WA 486ms19788kbC++144.3kb2023-04-19 19:37:172023-04-19 19:37:20

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-19 19:37:20]
  • 评测
  • 测评结果:WA
  • 用时:486ms
  • 内存:19788kb
  • [2023-04-19 19:37:17]
  • 提交

answer

#include <bits/stdc++.h>

template <class T>
inline void read(T &res)
{
	char ch; bool flag = false; res = 0;
	while (ch = getchar(), !isdigit(ch) && ch != '-');
	ch == '-' ? flag = true : res = ch ^ 48;
	while (ch = getchar(), isdigit(ch))
		res = res * 10 + ch - 48;
	flag ? res = -res : 0;
}

template <class T>
inline void nonnegative_put(T x)
{
	if (x > 9)
		nonnegative_put(x / 10);
	putchar(x % 10 + 48);
}

template <class T>
inline void put(T x)
{
	if (x < 0)
		x = -x, putchar('-');
	nonnegative_put(x);
}

template <class T>
inline void CkMin(T &x, T y) {x > y ? x = y : 0;}
template <class T>
inline void CkMax(T &x, T y) {x < y ? x = y : 0;}
template <class T>
inline T Min(T x, T y) {return x < y ? x : y;}
template <class T>
inline T Max(T x, T y) {return x > y ? x : y;}
template <class T>
inline T Abs(T x) {return x < 0 ? -x : x;}
template <class T>
inline T Sqr(T x) {return x * x;} 
//call Sqr((ll)x) when the type of returned value is "long long".

using std::map;
using std::set;
using std::pair;
using std::bitset;
using std::string;
using std::vector;
using std::complex;
using std::multiset;
using std::priority_queue;

typedef long long ll;
typedef long double ld;
typedef complex<ld> com;
typedef pair<int, int> pir;
const ld pi = acos(-1.0);
const ld eps = 1e-8;
const int Maxn = 1e9;
const int Minn = -1e9;
const int mod = 998244353; 
const int N = 14e3 + 5;

vector<int> e[N], re[N];
int ans[N], ind[N], dfn[N], low[N], stk[N], col[N]; 
bool ins[N];
bitset<N> vis[N];
int T_data, n, m, C, top, tis;

const int M = 7e4 + 5;
int nxt[M], to[M], cap[M], adj[N], que[N], cur[N], lev[N];
int src, des, qr, T = 1;

inline void linkArc(int x, int y, int w)
{
	nxt[++T] = adj[x]; adj[x] = T; to[T] = y; cap[T] = w;
	nxt[++T] = adj[y]; adj[y] = T; to[T] = x; cap[T] = 0;	
}

inline bool Bfs()
{
	for (int x = 1; x <= des; ++x)	
		cur[x] = adj[x], lev[x] = -1;
	// 初始化具体的范围视建图而定,这里点的范围为 [1,n]
	que[qr = 1] = src;
	lev[src] = 0;
	for (int i = 1; i <= qr; ++i)
	{
		int x = que[i], y;
		for (int e = adj[x]; e; e = nxt[e])
			if (cap[e] > 0 && lev[y = to[e]] == -1)
			{
				lev[y] = lev[x] + 1;
				que[++qr] = y;
				if (y == des)
					return true;
			}
	}
	return false;
} 

inline int Dinic(int x, int flow)
{
	if (x == des)
		return flow;
	int y, delta, res = 0;	
	for (int &e = cur[x]; e; e = nxt[e]) 
		if (cap[e] > 0 && lev[y = to[e]] > lev[x])
		{
			delta = Dinic(y, Min(flow - res, cap[e]));
			if (delta)
			{
				cap[e] -= delta;
				cap[e ^ 1] += delta;
				res += delta;
				if (res == flow)
					break ; 
				//此时 break 保证下次 cur[x] 仍有机会增广 
			}
		} 
	if (res != flow)
		lev[x] = -1;
	return res; 
}

inline int maxFlow()
{
	int res = 0;
	while (Bfs())
		res += Dinic(src, Maxn);
	return res;
}

inline void Tarjan(int x)
{
	dfn[x] = low[x] = ++tis;
	stk[++top] = x;
	ins[x] = true; 
	for (int y : e[x])
		if (!dfn[y])
		{
			Tarjan(y);
			CkMin(low[x], low[y]);
		}
		else if (ins[y])
			CkMin(low[x], dfn[y]);
	if (dfn[x] == low[x])
	{
		int y;
		++C;
		do
		{
			y = stk[top--];
			ins[y] = false;
			col[y] = C;
		}while (y != x);
	}
}

inline void dfs(int x)
{
	ans[x] = tis;
	for (int y : re[x])
		if (ind[y])
		{
			--ind[y];
			dfs(y);
			return ;
		}			
}

int main()
{
	read(n); read(m);
	for (int i = 1, x, y; i <= m; ++i)
	{
		read(x); read(y);
		e[x].emplace_back(y);
	}
	for (int i = 1; i <= n; ++i)
		if (!dfn[i])
			Tarjan(i);
	for (int x = 1; x <= n; ++x)
	{
		for (int y : e[x])
			if (col[x] != col[y])
				vis[col[x]][col[y]] = 1;
		e[x].clear();
	}
	src = (C << 1) | 1, des = src + 1;
	for (int x = 1; x <= C; ++x)
	{
		linkArc(src, x, 1);
		linkArc(x + C, des, 1);
		linkArc(x + C, x, Maxn);
		for (int y = 1; y <= C; ++y)
			if (vis[x][y])
				linkArc(x, y + C, Maxn);
	}
	int _ans = maxFlow();
	for (int x = 1; x <= C; ++x)
		for (int e = adj[x]; e; e = nxt[e])
			if (!(e & 1) && to[e] > C && to[e] < src && to[e] - C != x && cap[e] < Maxn)
			{
				re[x].emplace_back(to[e] - C);
				ind[to[e] - C] += Maxn - cap[e];
			}
	tis = 0;
	for (int x = 1; x <= C; ++x)
		if (!ind[x])
		{
			++tis;
			dfs(x);
		}
	for (int i = 1; i <= n; ++i)
		put(ans[col[i]]), putchar(' ');
	putchar('\n');
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 5572kb

input:

5 5
1 4
2 3
1 3
2 5
5 1

output:

2 2 2 1 2 

result:

ok AC

Test #2:

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

input:

5 7
1 2
2 1
4 3
5 1
5 4
4 1
4 5

output:

1 1 2 2 2 

result:

ok AC

Test #3:

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

input:

8 6
6 1
3 4
3 6
2 3
4 1
6 4

output:

1 1 1 1 2 1 3 4 

result:

ok AC

Test #4:

score: 0
Accepted
time: 348ms
memory: 17748kb

input:

7000 6999
4365 4296
2980 3141
6820 4995
4781 24
2416 5844
2940 2675
3293 2163
3853 5356
262 6706
1985 1497
5241 3803
353 1624
5838 4708
5452 3019
2029 6161
3849 4219
1095 1453
4268 4567
1184 1857
2911 3977
1662 2751
6353 6496
2002 6628
1407 4623
425 1331
4445 4277
1259 3165
4994 1044
2756 5788
5496 ...

output:

1 1644 1337 1548 1746 2 3 1374 1096 246 1750 1750 4 1750 1519 5 1235 6 1049 1726 1253 1166 1747 1498 1649 7 8 1730 1417 9 580 1185 10 11 1366 1366 1465 12 1747 13 226 1137 14 1217 15 1064 16 1747 17 18 872 19 459 1746 1629 1564 1747 20 720 21 1176 1746 1746 1747 1593 22 1747 1747 1508 23 24 1041 25 ...

result:

ok AC

Test #5:

score: 0
Accepted
time: 432ms
memory: 17432kb

input:

7000 6999
4832 1603
5984 6985
5355 3687
6007 2170
5984 3486
3267 2189
538 2123
4343 4553
5855 6168
5984 257
4239 2304
5984 2063
3298 1869
5984 6353
5984 2018
5984 5387
5984 3382
3164 3978
2690 2816
4810 2638
5984 3773
5984 1634
5984 2786
5984 3671
5984 5140
2943 5721
5984 414
1105 4060
3093 796
5984...

output:

2332 2332 1716 1869 611 2332 1448 1663 2332 2324 2324 2332 2332 1060 2333 1 2332 2332 2332 4 2 621 239 1102 2332 2332 1486 438 1552 766 670 2332 2332 2332 3 4 963 2332 2217 2199 5 2097 1147 6 488 7 2313 8 9 761 2316 801 31 2130 523 2332 10 11 12 13 2332 2332 14 2324 1529 776 2332 1717 2332 70 15 233...

result:

ok AC

Test #6:

score: 0
Accepted
time: 486ms
memory: 18908kb

input:

7000 6999
1649 5337
1701 3344
4394 2172
3330 39
5932 1141
5381 5340
5453 3300
125 2172
6810 5263
804 2172
6635 2172
676 4740
3015 1183
1710 5769
611 5915
3419 1581
2094 2172
4508 2172
6604 2433
6113 1466
1604 696
1518 1123
1287 2940
4825 2172
5130 4524
2693 2172
106 2172
5157 2172
3693 2172
5198 217...

output:

1 2 1870 2015 2231 3 2169 1250 614 4 1186 5 6 1432 1702 1805 7 1949 1176 644 1633 8 9 888 1783 2068 1603 1921 10 11 542 12 1000 1582 924 13 1923 1913 2240 14 2097 261 593 15 1949 1159 1649 2031 16 2289 1957 17 662 796 1640 2011 2011 18 1751 2329 19 2272 20 151 507 440 2113 1521 21 22 23 24 25 1256 1...

result:

ok AC

Test #7:

score: 0
Accepted
time: 151ms
memory: 19364kb

input:

7000 6999
2896 6321
881 2623
5058 2623
4833 2623
4669 2623
4781 5007
1447 2623
4781 4768
4781 3834
2758 4792
797 5055
3784 2623
4781 5510
6606 3040
597 3459
4136 2037
1291 3989
4781 837
4781 4379
5637 2053
1642 2665
4781 4664
4781 952
4924 2511
4781 4201
4781 2352
4781 5362
3901 197
137 2623
2706 19...

output:

1 1750 1750 1750 1750 1750 1750 2 1397 3 1750 1750 1750 1750 1750 308 203 1750 1750 4 406 1750 956 1144 384 247 323 744 5 6 1750 7 1750 1750 1750 1750 215 1525 1750 1052 1750 1750 872 1750 8 1750 9 1750 10 1750 1750 1750 11 12 1750 13 1750 1750 968 1750 14 1750 1750 1638 1750 15 1479 252 1750 8 1750...

result:

ok AC

Test #8:

score: 0
Accepted
time: 40ms
memory: 15196kb

input:

6999 6998
1269 3969
1269 2429
1269 2609
1269 2515
1269 6166
1269 6614
3108 1269
2105 1269
4670 1269
578 1269
4661 1269
1421 1269
2576 1269
6152 1269
1269 6636
3011 1269
305 1269
5189 1269
1683 1269
6861 1269
1269 5798
1499 1269
282 1269
914 1269
80 1269
677 1269
701 1269
1269 359
6521 1269
1269 1754...

output:

1 2 3 4 2427 5 6 833 2455 255 196 554 7 3066 8 9 10 2524 11 12 3375 13 14 808 15 16 17 18 19 1825 20 2433 21 22 306 23 1886 3041 24 2985 2529 25 26 2296 412 27 28 29 30 31 978 1948 7 32 3237 1105 33 34 35 36 37 2923 3480 38 104 667 163 39 40 41 2975 42 2770 1755 1397 43 44 708 45 46 1405 47 1120 193...

result:

ok AC

Test #9:

score: 0
Accepted
time: 42ms
memory: 6540kb

input:

7000 0

output:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...

result:

ok AC

Test #10:

score: 0
Accepted
time: 40ms
memory: 19788kb

input:

7000 6999
3138 1903
3285 5919
6182 1430
1164 961
1577 6445
1390 3384
935 5723
6614 6387
4799 2877
3915 5128
5366 5455
2287 3941
2053 2326
4022 6993
488 2922
4327 4701
4674 3221
1666 4773
4356 3232
3888 937
4318 6942
577 1299
4491 1938
5154 1254
790 5532
4286 5478
2918 6725
2853 304
2554 5207
5140 77...

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 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 AC

Test #11:

score: 0
Accepted
time: 9ms
memory: 12700kb

input:

7000 6999
33 3147
5877 4807
3116 4168
1651 2456
624 1740
6440 3058
6414 489
1023 2523
706 93
5523 598
4211 6063
3570 6840
6566 2971
6614 1907
5893 4389
4022 2527
5096 2345
4682 2134
188 5597
695 4285
1344 3832
3534 879
6574 6252
3759 3444
2167 85
5630 6600
3158 4404
6389 689
4871 6719
4295 6008
3437...

output:

44 50 70 70 40 40 70 67 70 70 70 70 70 1 70 67 70 41 70 70 20 70 50 70 70 70 70 70 70 70 70 70 2 70 70 67 7 28 70 70 70 40 16 70 3 70 20 70 70 67 70 70 70 70 70 67 70 70 70 48 20 7 7 70 70 70 70 71 50 70 65 50 70 70 40 70 53 71 50 70 44 27 70 70 13 55 70 70 27 70 50 70 70 70 70 31 4 70 13 70 70 70 7...

result:

ok AC

Test #12:

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

input:

7000 6999
1247 5150
3318 2013
5686 1615
6145 6521
5717 94
2787 3443
2648 4875
5332 5934
1897 1651
4640 2183
1750 6964
148 5228
745 2814
474 1165
496 6735
180 3412
2723 3374
6200 4361
497 5328
1928 5998
5648 1261
5090 4723
1715 706
2499 897
6569 6204
6039 2787
2882 5044
5767 4256
975 1877
1857 4453
6...

output:

274 1 274 62 274 274 72 274 218 274 16 259 74 274 274 75 274 274 274 274 274 274 274 274 274 274 213 274 130 2 274 274 274 274 274 274 195 274 115 274 274 274 215 274 274 62 274 274 274 176 232 3 274 274 274 274 274 49 16 274 62 84 274 274 274 259 274 274 20 104 274 268 130 274 274 274 274 274 4 68 ...

result:

ok AC

Test #13:

score: 0
Accepted
time: 23ms
memory: 17192kb

input:

7000 6999
2349 199
5295 2831
6143 2006
3212 3198
6956 3807
732 4838
5069 1027
5744 3479
6 5301
5687 4452
4201 1151
1353 4884
548 3506
6094 4799
4950 6939
5234 817
652 1314
979 6984
5771 1851
398 1322
2294 4298
847 3929
6833 183
2904 6745
4797 3874
94 315
4282 582
6591 5037
962 147
799 908
2593 5547
...

output:

1049 1 105 1049 1049 354 880 565 666 259 385 1049 1034 348 955 1049 668 676 2 410 998 1049 1049 3 846 1049 1049 4 451 1049 308 769 741 264 1049 445 1049 1011 622 236 934 1049 393 764 1049 5 992 1049 1049 6 845 466 7 8 961 9 259 414 10 759 1049 1049 277 1049 1049 889 105 374 92 376 1049 1049 1049 104...

result:

ok AC

Test #14:

score: 0
Accepted
time: 27ms
memory: 17312kb

input:

7000 6999
3409 1629
2076 6412
4997 1078
6320 626
4501 1104
4173 1774
5507 2375
2299 5115
4321 127
1192 6635
1909 3398
2972 499
862 5024
421 2931
861 1536
902 3813
659 4514
1843 3035
3669 1228
1724 1880
34 706
133 3468
6116 585
5073 1461
5667 3405
715 4834
6915 3007
1736 6108
3264 2870
2393 6474
2108...

output:

815 2604 1 1647 2604 2 1001 2604 1867 3 1554 4 2604 5 6 2421 136 2604 999 1808 2604 7 2604 1684 8 2604 9 10 11 12 2604 13 2604 14 97 933 1995 1471 15 1080 2217 1323 296 576 2604 90 292 509 16 2364 620 1356 2604 2104 2604 2453 885 2520 17 18 2251 2604 901 19 2382 20 125 21 2302 22 732 1149 23 1469 11...

result:

ok AC

Test #15:

score: -100
Wrong Answer
time: 48ms
memory: 18488kb

input:

7000 7000
2048 5882
6801 2408
3225 2608
1441 5079
497 6253
557 5589
2535 6257
4800 2595
4713 1286
4759 6636
4303 4296
6195 2048
6994 2987
1249 3044
1036 10
6472 2076
1996 1086
1279 1486
6100 369
4797 3437
2493 4576
2944 5601
197 5582
5488 5035
4023 659
2651 5024
2257 5710
1001 3941
446 4815
687 702
...

output:

1 2 3 4 5 7 2008 10 11 619 13 534 17 1903 2799 2292 34 35 895 2650 1099 36 827 2356 37 208 539 2476 41 1379 48 49 2557 1625 1632 51 52 53 1473 54 55 56 57 990 1127 58 59 749 1446 312 61 217 62 1872 64 1520 65 1415 67 1109 68 719 2521 70 933 71 990 2886 72 1477 75 749 1804 238 76 1803 78 2578 82 83 1...

result:

wrong answer Integer 0 violates the range [1, 3009]