提出 #10746815
ソースコード 拡げる
/*
`
`
`
`
`
`
`
`
`!!!;' `
'%$@########################&&%:. `
.%###################################%. `
.`|######################################% `
.!@###############################################$' `
.!@#########################@@@#########################&;. `
:@##################@@@&&@@@$!!%&@@@@@@@###################&' `
:&################@@@&$%%||||!!:'':;!!||%|!%&@@#################%` `
|###############@@&&$%|!;;::::':'''':::;;!!|%%%$&&@###############$` `
:&#############@&$%||||!;'````````````'''```'':::'':!|$@@###############; `
:@#############@$$%|!;;;;:'``````...```...`...`'':::''';|%$$$&############&' `
|##############&$$$%||!!;:'`````..````....`...```''::::;!!||$&&@@###########&' `
!##############@$%|!!!;::'''`````...``.....`````````'''::::;;::!|%$&############| `
:@##########@&%!:'`::;;:'``....```....... .``....````````````'':;!|%$@############; `
;##########@%;```...`'''`... ..... ................ .`. `:!!!!%%%&#########| `
;##########&|:.`'`. ..`... ....... ..... .. ..... ... .'':!!:.`''!@#########|. `
!##########|'`.;!` . ...... .. . .... .::'`. .. .`'|@########@: `
;##########%'`'%! .. . . .. .```. ';:`..``.`':|@########@: `
!##########$:;$&; . `|%;. `;||;::`.``';;. .;!: `;:`';|$#########@!. `
!##########@$&@|. ...... .`':!|;` !$|%%'!##$' `|####$:`:;:!&$:. '$&!';!!||%&############; `
`$#############&: `!!'`:;;;||%@&!'!&&$;.|##%`.|#####%`'$@$&##%` .:||;;;;%@##############! `
:@#############|. .!&@|;%@@@@@&@@#@&@#@&@############@@#####@: .`'%@%!!&###############! `
:@############@; :&@!;$###@|%|!$@@######################@%` .;|!;!|%@###############! `
:@############@: `$#$%#@@##&@################@$$$&$%|!' `%#@|;':|&###############! `
!##########@$%: |####@&######$;. ..`'` ;@##############! `
!##########! ;#########|. `;` ;###############! `
;##########; `%######; '$###&: `%@############&' `
!########@: .'. .:;` .|%: !##########&' `
!########@: ;#########@: `
!######%. !##&;. . `%&!` '&###&' !#########! `
|#######;.%###! `!&###@|;;%@###%. ';;|&$:;;` |#%. .%###%$###! `
!#######| `%#&' |##&$####&: !##########; `%#####%.!#|. .%@: ;###;`%##! `
!#$!$##! :@#! .|###$'. ;##|. :&#@; .``::` ;@|. :@#@: `$#| `
:&&|&##; :&#! :&##; .%##! !&' ;@##! |#! `
|@@##@; .`%#! '$##; ;##$` :@! .|##@; :&! `
!&|&##%:'. :&! :@#%. .%##; |&!. `|@! `$! `
'$%%###&;. '&&' `%##&' |##@&: ...;&&&@; .;&#|':;$&: `
.|######&; '$@@@@@@@@#| :&######%` `
!#####&: '$#####@: `
'$#####@: ;#####$` `
'&####%. `` '$#####; `
!#####$' |@: .:%|;;;;!$#####@#| '&###$: `
:&####&: ;####################@: ':` `%###@: `
;#####@%:. `'';|@######$` `
`$######@|` !#&||@#####$` `
:&######@%'. .`''''` .';!|%@#@$$@####&: `
|######@|'. ;##$!!%@##########################@: '$####; `
:&#####$;''.`%#########&' `|@$: .%###@; `
:@####@; |#@##&$; `|%' .|####! `
!####@; . |####! `
:@###@|` . `|!. |####%. `
.|####! `;$@%|!!!!!%&&@#$;. !#####| `
.%####&: '%&@@@|` '&#####| `
.%#####|. :&######%` `
:|||;` !#######; .%#####@@#####@$;. `
`$#############&%!%#####|. :@####%:..'!&######@; `
`$#############|`..'%#######! ;####&;. .'%#######! `
.|##############@!` .'%#########%'. '%#####%` :@#######@%;:. `
;%|;. !############%::;' `!&############@&&@#######@%' !###########&' `
!################$' .:' '|&######################$:. :@#############@@@@@@; `
';$##&;:&###########$` :|$@################%:. !#####################@; `
'%####@$!:. `%#########! .:!%&@#######@%!;'. |##############%!$@####! `
.|#######&;'. . |#######%. .':;!!!!!!;`... .|############|. :$@@####%. `
!####&$&@#@!:'. ;#####%` .`';;'... ..''``. !##########%` ''':$######$` `
;#####@$$;`%&:. `%####; .:;;:'':;||!:` !#########! :&#@@####! `
'%######@######! !! :$@$` ...`.'::`.. '$######@!` '|$$&!!@#######@!. `
'$#########@&$$@######@: ;: . `' .... ...``. `$######&' '!;`'!@######&&########$' `
;############@#@@@@@$|%@###$` `!!.;' . :!. .%#####!. .;::&####|`..` ..;@########!'
|########&|;'``..`:' ..!##%:. ;; `. .|###|` `'|###@&$|` .. .`|&&@#######%:
|###@#@@#&|:`.`';;:;!!!;:;''!$##&;'. .'%; .;&###&|$! '$; .|$:;|` ...;&###$' .... :||%&########%:
|#######@$;!%%:``` .!@###&|` :|'!########@#! ;@! :@####%'. `|@###&: ..`:::%$$&$$$&@##@@@##|:
|########$;::'` .`. `%#####%!: .. !#####%` !#%. !; '%; !#############&: `::`.```. .':. :$@&&&###|:
!####@%:::;;:::::` ......... '. !#######%;;';; `%#&' ;&: `;``$@!%########&&##&|::::'. ':. `!%@@######|:
!#####%;;::. ...... ....`.. .. '::!|&########$';%`.'` .;%: !#$';$%|&$!&##########$' `';;;;!&##&%||||||%;` .:|&###@###|:
|#######|`... `|$&&$$!`.... ;$: :&#@: `'''``. .%########&' .%#@&$%$#####$` ....`:%&@@@@@@&&@@!`. .`'%@#######|'
|######@@$: .`..`!@&$&&&&: ;@#######@@#$%@######&$; '%@##%!@###@&&@####%. `!&@@@@@$:..`..``.``... `|&####@@##!'
;###&|;::!&#&%%%%: .'::::;|$&&$%|'..;%%&#######%;$########@&#####%` '|@###; '%####$;::::::` '!|%%%%%%%%%&#$:'::.'%###|'
`%###@|;|%$%$@#&|;::::` '|%%%%%$%|%|;';$##@|'. |######&' .:|$%: :&@|'. !####%. `::;:!$@######&%%%%%!' ':;&##|:
'$##%:. :&##@####@$;. .. `$| :; !#####| '|%: `` ... !####! . ..:&#@@@@##@&||$; :&####|'
!####&@@&; ...`.'%@##@@#@@&!` :&&!. !###&' :||:.` !%' ``:$######@@@&&@@@&@##$;``.... |@@@@########!'
!#######@$||!: ';!;;;!&###&|||||||||||%&##@!`. !###&||%!!!: .:;` `;;%####$;:;;;;;;;;;;;::. '||||||&#####%!;;$##!`
`%#&:.`:!||||||%@#@%;::;;;' ;@@: .. .%###|. `:::' .:!;'`':'` `$####! ':;;;;!%@@&%%%|;` `;%&###|:
.%##|.. '$##@@@@@@#&:...`.. `$#$' !##%` ..`.`:%@@! '%@$:''. .`|####|... .........`:%###@#@@@|` ....`%#####|:
!###@&! .`.```':!&##@&&&&$: '&#%. !#&' ````. .```:%&&&&&@#####@!':|$&&$&&&&&&&&&@##|`````. !@@@#######!'
:&#########@$||||: `::::;;;;;!!;;;:;$###$' .'` |#@|. .:;;:. `%####%:''':::::` `!||&##$;;;:::. ;##|:
.%#@$%$%%%%%$@###$::::::'. ...`;|!::!&##@$%|||!' .%##&%%$%' `'. :&####! .':::'::%@&$%%!` .!!':;$###%:
:&#############@|. . '$##################&;..!@###@#######%'. .!#####! . `$#####@|``;&|!&####|:
|####&%' .''''':|@###@$$$$$$%;. |####%` .|#@;. .;$$$%$&$$$$$$&######$:..:|%$$$$$$$&&&&@######&;'''. ;$&########|:
|#######@%;;` '!|!||$#######&|!!!;;;!!!;`.!#####@: .;|!!|&#$' `:'':;;$######################################%!|!!!!!;. .`;|&######@####%:
|############$!''''..';$&&&&@########################$;'!;`:@#&:``'|$@######@@@@&&&&&&&@#######@&&&&&&&&&&&@@&&&&$|:. .`''$########@&@####%:
|###&%$&#################@%;' .. `|@############$: `%@###########$` `%%:. . :@######| !#####################@$%&##########%:
|#######################################@&&@######################@@&@#######################################################################%:
*/
#define _CRT_SECURE_NO_WARNINGS
#include <map>
#include <set>
#include <stack>
#include <ctime>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cctype>
#include <vector>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;
inline char gc() {
static const int L = 233333;
static char sxd[L], *sss = sxd, *ttt = sxd;
if (sss == ttt) {
ttt = (sss = sxd) + fread(sxd, 1, L, stdin);
if (sss == ttt) {
return EOF;
}
}
return *sss++;
}
#ifndef _AT_HOME
#define dd c = gc()
#else
#define dd c = getchar()
#endif
inline char readalpha() {
char dd;
for (; !isalpha(c); dd);
return c;
}
inline char readchar() {
char dd;
for (; c == ' '; dd);
return c;
}
template <class T>
inline bool read(T& x) {
bool flg = false;
char dd;
x = 0;
for (; !isdigit(c); dd) {
if (c == '-') {
flg = true;
} else if(c == EOF) {
return false;
}
}
for (; isdigit(c); dd) {
x = (x * 10) + (c ^ 48);
}
if (flg) {
x = -x;
}
return true;
}
#undef dd
template <class T>
inline void write(T x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x < 10) {
putchar(x | 48);
return;
}
write(x / 10);
putchar((x % 10) | 48);
}
template <class T>
inline void writesp(T x) {
write(x);
putchar(' ');
}
template <class T>
inline void writeln(T x) {
write(x);
puts("");
}
#define lowbit(x) (x & -x)
namespace dfcmd {
const int maxn = 50005;
const int maxm = 100005;
int n, m, T;
struct Balancer {
int x, y;
} bal[maxm];
char ans[maxm];
int ff[maxn];
namespace solve1 {
bitset<maxn> f[maxn];
inline void solve() {
for (int i = 1; i <= n; ++i) {
f[i][i] = 1;
}
for (int i = m; i; --i) {
f[bal[i].x] = f[bal[i].y] = f[bal[i].x] | f[bal[i].y];
}
for (int i = 2; i <= n; ++i) {
f[1] &= f[i];
}
int now = 0;
for (int i = 1; i <= n; ++i) {
if (f[1][i]) {
now = i;
break;
}
}
if (!now) {
puts("-1");
return;
}
ff[now] = 1;
for (int i = m; i; --i) {
if (ff[bal[i].x]) {
ans[i] = '^';
} else {
ans[i] = 'v';
}
ff[bal[i].x] = ff[bal[i].y] = ff[bal[i].x] | ff[bal[i].y];
}
puts(ans + 1);
}
}
namespace solve2 {
int g[maxn];
inline void solve() {
if (n == 2) {
puts("-1");
return;
}
for (int i = 1; i <= n; ++i) {
ff[i] = i;
g[i] = 1;
}
for (int i = m; i; --i) {
if (g[ff[bal[i].x]] < g[ff[bal[i].y]]) {
g[ff[bal[i].x]]++, g[ff[bal[i].y]]--;
ff[bal[i].y] = ff[bal[i].x];
ans[i] = '^';
} else {
g[ff[bal[i].x]]--, g[ff[bal[i].y]]++;
ff[bal[i].x] = ff[bal[i].y];
ans[i] = 'v';
}
}
puts(ans + 1);
}
}
int Main() {
read(n), read(m), read(T);
for (int i = 1; i <= m; ++i) {
read(bal[i].x), read(bal[i].y);
}
if (T == 1) {
solve1::solve();
} else {
solve2::solve();
}
return 0;
}
}
int main() {
return dfcmd::Main();
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | E - Balancing Network |
| ユーザ | pufanyi |
| 言語 | C++ (GCC 5.4.1) |
| 得点 | 1600 |
| コード長 | 18798 Byte |
| 結果 | AC |
| 実行時間 | 302 ms |
| メモリ | 307328 KiB |
ジャッジ結果
| セット名 | Sample | Uniforming | Non-uniforming | ||||||
|---|---|---|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 800 / 800 | 800 / 800 | ||||||
| 結果 |
|
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 00-sample-04.txt |
| Uniforming | 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt, 01-44.txt, 01-45.txt, 01-46.txt, 01-47.txt, 01-48.txt, 01-49.txt, 01-50.txt, 01-51.txt, 01-52.txt, 01-53.txt, 01-54.txt, 01-55.txt |
| Non-uniforming | 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt, 02-17.txt, 02-18.txt, 02-19.txt, 02-20.txt, 02-21.txt, 02-22.txt, 02-23.txt, 02-24.txt, 02-25.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00-sample-01.txt | AC | 78 ms | 305792 KiB |
| 00-sample-02.txt | AC | 78 ms | 305792 KiB |
| 00-sample-03.txt | AC | 78 ms | 305792 KiB |
| 00-sample-04.txt | AC | 78 ms | 305792 KiB |
| 01-01.txt | AC | 78 ms | 305792 KiB |
| 01-02.txt | AC | 78 ms | 305792 KiB |
| 01-03.txt | AC | 78 ms | 305792 KiB |
| 01-04.txt | AC | 78 ms | 305792 KiB |
| 01-05.txt | AC | 78 ms | 305792 KiB |
| 01-06.txt | AC | 78 ms | 305792 KiB |
| 01-07.txt | AC | 78 ms | 305792 KiB |
| 01-08.txt | AC | 174 ms | 306944 KiB |
| 01-09.txt | AC | 174 ms | 306944 KiB |
| 01-10.txt | AC | 174 ms | 306944 KiB |
| 01-11.txt | AC | 78 ms | 305792 KiB |
| 01-12.txt | AC | 78 ms | 305792 KiB |
| 01-13.txt | AC | 78 ms | 305792 KiB |
| 01-14.txt | AC | 78 ms | 305792 KiB |
| 01-15.txt | AC | 78 ms | 305792 KiB |
| 01-16.txt | AC | 78 ms | 305792 KiB |
| 01-17.txt | AC | 175 ms | 306944 KiB |
| 01-18.txt | AC | 175 ms | 306944 KiB |
| 01-19.txt | AC | 175 ms | 306944 KiB |
| 01-20.txt | AC | 80 ms | 305792 KiB |
| 01-21.txt | AC | 80 ms | 305792 KiB |
| 01-22.txt | AC | 80 ms | 305792 KiB |
| 01-23.txt | AC | 80 ms | 305792 KiB |
| 01-24.txt | AC | 80 ms | 305792 KiB |
| 01-25.txt | AC | 80 ms | 305792 KiB |
| 01-26.txt | AC | 194 ms | 306944 KiB |
| 01-27.txt | AC | 196 ms | 306944 KiB |
| 01-28.txt | AC | 190 ms | 306944 KiB |
| 01-29.txt | AC | 110 ms | 305792 KiB |
| 01-30.txt | AC | 110 ms | 305792 KiB |
| 01-31.txt | AC | 110 ms | 305792 KiB |
| 01-32.txt | AC | 112 ms | 305792 KiB |
| 01-33.txt | AC | 112 ms | 305792 KiB |
| 01-34.txt | AC | 112 ms | 305792 KiB |
| 01-35.txt | AC | 277 ms | 307200 KiB |
| 01-36.txt | AC | 269 ms | 307200 KiB |
| 01-37.txt | AC | 240 ms | 307200 KiB |
| 01-38.txt | AC | 190 ms | 306432 KiB |
| 01-39.txt | AC | 189 ms | 306688 KiB |
| 01-40.txt | AC | 177 ms | 306688 KiB |
| 01-41.txt | AC | 191 ms | 306432 KiB |
| 01-42.txt | AC | 190 ms | 306688 KiB |
| 01-43.txt | AC | 180 ms | 306688 KiB |
| 01-44.txt | AC | 181 ms | 306688 KiB |
| 01-45.txt | AC | 181 ms | 306432 KiB |
| 01-46.txt | AC | 177 ms | 306688 KiB |
| 01-47.txt | AC | 169 ms | 306688 KiB |
| 01-48.txt | AC | 302 ms | 306816 KiB |
| 01-49.txt | AC | 279 ms | 307200 KiB |
| 01-50.txt | AC | 279 ms | 307200 KiB |
| 01-51.txt | AC | 279 ms | 307200 KiB |
| 01-52.txt | AC | 301 ms | 307200 KiB |
| 01-53.txt | AC | 280 ms | 307200 KiB |
| 01-54.txt | AC | 285 ms | 307200 KiB |
| 01-55.txt | AC | 280 ms | 307200 KiB |
| 02-01.txt | AC | 78 ms | 305792 KiB |
| 02-02.txt | AC | 80 ms | 306816 KiB |
| 02-03.txt | AC | 80 ms | 306944 KiB |
| 02-04.txt | AC | 80 ms | 306944 KiB |
| 02-05.txt | AC | 80 ms | 306944 KiB |
| 02-06.txt | AC | 80 ms | 306944 KiB |
| 02-07.txt | AC | 81 ms | 306944 KiB |
| 02-08.txt | AC | 81 ms | 306944 KiB |
| 02-09.txt | AC | 80 ms | 306944 KiB |
| 02-10.txt | AC | 81 ms | 306944 KiB |
| 02-11.txt | AC | 81 ms | 306944 KiB |
| 02-12.txt | AC | 81 ms | 306944 KiB |
| 02-13.txt | AC | 81 ms | 306944 KiB |
| 02-14.txt | AC | 81 ms | 306944 KiB |
| 02-15.txt | AC | 81 ms | 306944 KiB |
| 02-16.txt | AC | 81 ms | 306944 KiB |
| 02-17.txt | AC | 81 ms | 306944 KiB |
| 02-18.txt | AC | 81 ms | 306944 KiB |
| 02-19.txt | AC | 81 ms | 306944 KiB |
| 02-20.txt | AC | 81 ms | 306944 KiB |
| 02-21.txt | AC | 82 ms | 307072 KiB |
| 02-22.txt | AC | 82 ms | 307328 KiB |
| 02-23.txt | AC | 81 ms | 306944 KiB |
| 02-24.txt | AC | 80 ms | 306944 KiB |
| 02-25.txt | AC | 81 ms | 306944 KiB |