Please sign in first.
Submission #10301461
Source Code Expand
/*
`
`
`
`
`
`
`
`
`!!!;' `
'%$@########################&&%:. `
.%###################################%. `
.`|######################################% `
.!@###############################################$' `
.!@#########################@@@#########################&;. `
:@##################@@@&&@@@$!!%&@@@@@@@###################&' `
:&################@@@&$%%||||!!:'':;!!||%|!%&@@#################%` `
|###############@@&&$%|!;;::::':'''':::;;!!|%%%$&&@###############$` `
:&#############@&$%||||!;'````````````'''```'':::'':!|$@@###############; `
:@#############@$$%|!;;;;:'``````...```...`...`'':::''';|%$$$&############&' `
|##############&$$$%||!!;:'`````..````....`...```''::::;!!||$&&@@###########&' `
!##############@$%|!!!;::'''`````...``.....`````````'''::::;;::!|%$&############| `
:@##########@&%!:'`::;;:'``....```....... .``....````````````'':;!|%$@############; `
;##########@%;```...`'''`... ..... ................ .`. `:!!!!%%%&#########| `
;##########&|:.`'`. ..`... ....... ..... .. ..... ... .'':!!:.`''!@#########|. `
!##########|'`.;!` . ...... .. . .... .::'`. .. .`'|@########@: `
;##########%'`'%! .. . . .. .```. ';:`..``.`':|@########@: `
!##########$:;$&; . `|%;. `;||;::`.``';;. .;!: `;:`';|$#########@!. `
!##########@$&@|. ...... .`':!|;` !$|%%'!##$' `|####$:`:;:!&$:. '$&!';!!||%&############; `
`$#############&: `!!'`:;;;||%@&!'!&&$;.|##%`.|#####%`'$@$&##%` .:||;;;;%@##############! `
:@#############|. .!&@|;%@@@@@&@@#@&@#@&@############@@#####@: .`'%@%!!&###############! `
:@############@; :&@!;$###@|%|!$@@######################@%` .;|!;!|%@###############! `
:@############@: `$#$%#@@##&@################@$$$&$%|!' `%#@|;':|&###############! `
!##########@$%: |####@&######$;. ..`'` ;@##############! `
!##########! ;#########|. `;` ;###############! `
;##########; `%######; '$###&: `%@############&' `
!########@: .'. .:;` .|%: !##########&' `
!########@: ;#########@: `
!######%. !##&;. . `%&!` '&###&' !#########! `
|#######;.%###! `!&###@|;;%@###%. ';;|&$:;;` |#%. .%###%$###! `
!#######| `%#&' |##&$####&: !##########; `%#####%.!#|. .%@: ;###;`%##! `
!#$!$##! :@#! .|###$'. ;##|. :&#@; .``::` ;@|. :@#@: `$#| `
:&&|&##; :&#! :&##; .%##! !&' ;@##! |#! `
|@@##@; .`%#! '$##; ;##$` :@! .|##@; :&! `
!&|&##%:'. :&! :@#%. .%##; |&!. `|@! `$! `
'$%%###&;. '&&' `%##&' |##@&: ...;&&&@; .;&#|':;$&: `
.|######&; '$@@@@@@@@#| :&######%` `
!#####&: '$#####@: `
'$#####@: ;#####$` `
'&####%. `` '$#####; `
!#####$' |@: .:%|;;;;!$#####@#| '&###$: `
:&####&: ;####################@: ':` `%###@: `
;#####@%:. `'';|@######$` `
`$######@|` !#&||@#####$` `
:&######@%'. .`''''` .';!|%@#@$$@####&: `
|######@|'. ;##$!!%@##########################@: '$####; `
:&#####$;''.`%#########&' `|@$: .%###@; `
:@####@; |#@##&$; `|%' .|####! `
!####@; . |####! `
:@###@|` . `|!. |####%. `
.|####! `;$@%|!!!!!%&&@#$;. !#####| `
.%####&: '%&@@@|` '&#####| `
.%#####|. :&######%` `
:|||;` !#######; .%#####@@#####@$;. `
`$#############&%!%#####|. :@####%:..'!&######@; `
`$#############|`..'%#######! ;####&;. .'%#######! `
.|##############@!` .'%#########%'. '%#####%` :@#######@%;:. `
;%|;. !############%::;' `!&############@&&@#######@%' !###########&' `
!################$' .:' '|&######################$:. :@#############@@@@@@; `
';$##&;:&###########$` :|$@################%:. !#####################@; `
'%####@$!:. `%#########! .:!%&@#######@%!;'. |##############%!$@####! `
.|#######&;'. . |#######%. .':;!!!!!!;`... .|############|. :$@@####%. `
!####&$&@#@!:'. ;#####%` .`';;'... ..''``. !##########%` ''':$######$` `
;#####@$$;`%&:. `%####; .:;;:'':;||!:` !#########! :&#@@####! `
'%######@######! !! :$@$` ...`.'::`.. '$######@!` '|$$&!!@#######@!. `
'$#########@&$$@######@: ;: . `' .... ...``. `$######&' '!;`'!@######&&########$' `
;############@#@@@@@$|%@###$` `!!.;' . :!. .%#####!. .;::&####|`..` ..;@########!'
|########&|;'``..`:' ..!##%:. ;; `. .|###|` `'|###@&$|` .. .`|&&@#######%:
|###@#@@#&|:`.`';;:;!!!;:;''!$##&;'. .'%; .;&###&|$! '$; .|$:;|` ...;&###$' .... :||%&########%:
|#######@$;!%%:``` .!@###&|` :|'!########@#! ;@! :@####%'. `|@###&: ..`:::%$$&$$$&@##@@@##|:
|########$;::'` .`. `%#####%!: .. !#####%` !#%. !; '%; !#############&: `::`.```. .':. :$@&&&###|:
!####@%:::;;:::::` ......... '. !#######%;;';; `%#&' ;&: `;``$@!%########&&##&|::::'. ':. `!%@@######|:
!#####%;;::. ...... ....`.. .. '::!|&########$';%`.'` .;%: !#$';$%|&$!&##########$' `';;;;!&##&%||||||%;` .:|&###@###|:
|#######|`... `|$&&$$!`.... ;$: :&#@: `'''``. .%########&' .%#@&$%$#####$` ....`:%&@@@@@@&&@@!`. .`'%@#######|'
|######@@$: .`..`!@&$&&&&: ;@#######@@#$%@######&$; '%@##%!@###@&&@####%. `!&@@@@@$:..`..``.``... `|&####@@##!'
;###&|;::!&#&%%%%: .'::::;|$&&$%|'..;%%&#######%;$########@&#####%` '|@###; '%####$;::::::` '!|%%%%%%%%%&#$:'::.'%###|'
`%###@|;|%$%$@#&|;::::` '|%%%%%$%|%|;';$##@|'. |######&' .:|$%: :&@|'. !####%. `::;:!$@######&%%%%%!' ':;&##|:
'$##%:. :&##@####@$;. .. `$| :; !#####| '|%: `` ... !####! . ..:&#@@@@##@&||$; :&####|'
!####&@@&; ...`.'%@##@@#@@&!` :&&!. !###&' :||:.` !%' ``:$######@@@&&@@@&@##$;``.... |@@@@########!'
!#######@$||!: ';!;;;!&###&|||||||||||%&##@!`. !###&||%!!!: .:;` `;;%####$;:;;;;;;;;;;;::. '||||||&#####%!;;$##!`
`%#&:.`:!||||||%@#@%;::;;;' ;@@: .. .%###|. `:::' .:!;'`':'` `$####! ':;;;;!%@@&%%%|;` `;%&###|:
.%##|.. '$##@@@@@@#&:...`.. `$#$' !##%` ..`.`:%@@! '%@$:''. .`|####|... .........`:%###@#@@@|` ....`%#####|:
!###@&! .`.```':!&##@&&&&$: '&#%. !#&' ````. .```:%&&&&&@#####@!':|$&&$&&&&&&&&&@##|`````. !@@@#######!'
:&#########@$||||: `::::;;;;;!!;;;:;$###$' .'` |#@|. .:;;:. `%####%:''':::::` `!||&##$;;;:::. ;##|:
.%#@$%$%%%%%$@###$::::::'. ...`;|!::!&##@$%|||!' .%##&%%$%' `'. :&####! .':::'::%@&$%%!` .!!':;$###%:
:&#############@|. . '$##################&;..!@###@#######%'. .!#####! . `$#####@|``;&|!&####|:
|####&%' .''''':|@###@$$$$$$%;. |####%` .|#@;. .;$$$%$&$$$$$$&######$:..:|%$$$$$$$&&&&@######&;'''. ;$&########|:
|#######@%;;` '!|!||$#######&|!!!;;;!!!;`.!#####@: .;|!!|&#$' `:'':;;$######################################%!|!!!!!;. .`;|&######@####%:
|############$!''''..';$&&&&@########################$;'!;`:@#&:``'|$@######@@@@&&&&&&&@#######@&&&&&&&&&&&@@&&&&$|:. .`''$########@&@####%:
|###&%$&#################@%;' .. `|@############$: `%@###########$` `%%:. . :@######| !#####################@$%&##########%:
|#######################################@&&@######################@@&@#######################################################################%:
*/
#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 = 200005;
const int inf = 0x3f3f3f3f;
struct Edge {
int to, nxt, flow;
} e[maxn * 10];
int first[maxn];
int first_bak[maxn];
inline void add_edge(int from, int to) {
// cout << "edge " << from << ' ' << to << endl;
static int cnt = -1;
e[++cnt].nxt = first[from];
first[from] = cnt;
e[cnt].to = to;
e[cnt].flow = 1;
// cout << "edggg " << cnt << ' ' << from << ' ' << first[from] << ' ' << e[cnt].flow << endl;
e[++cnt].nxt = first[to];
first[to] = cnt;
e[cnt].to = from;
e[cnt].flow = 0;
}
int n, nn, S, T;
vector<int> dian[maxn];
vector<int> too[maxn];
int dep[maxn];
inline bool bfs() {
for (int i = 1; i <= n << 1; ++i) {
first[i] = first_bak[i];
}
queue<int> q;
memset(dep, 0, sizeof(dep));
dep[S] = 1;
q.push(S);
while (!q.empty()) {
int now = q.front();
// cout << "now = " << now << ' ' << first[now] << endl;
q.pop();
for (int i = first[now]; ~i; i = e[i].nxt) {
int to = e[i].to;
// cout << i << ' ' << e[i].to << ' ' << e[i].flow << endl;
if (!dep[to] && e[i].flow) {
dep[to] = dep[now] + 1;
q.push(to);
}
}
}
return dep[T];
}
inline int dfs(int now, int all) {
if (now == T) {
return all;
}
int flow = 0;
for (int i = first[now]; ~i; i = e[i].nxt) {
first[now] = i;
int to = e[i].to, f;
if (e[i].flow && dep[to] == dep[now] + 1 && (f = dfs(to, min(e[i].flow, all)))) {
all -= f;
flow += f;
e[i].flow -= f;
e[i ^ 1].flow += f;
}
}
return flow;
}
inline int Dinic() {
int ans = 0;
while (bfs()) {
ans += dfs(S, inf);
}
return ans;
}
int pp[maxn];
bool viss[maxn];
pair<int, int> ee[maxn];
inline int getans() {
for (int now = 1; now < n; ++now) {
for (int i = first[now]; ~i; i = e[i].nxt) {
int to = e[i].to;
if (!e[i].flow) {
pp[now] = to;
pp[to] = now;
break;
}
}
}
queue<int> q;
while (!q.empty()) {
q.pop();
}
q.push(n);
memset(viss, 0, sizeof(viss));
viss[n] = true;
int ans = 0;
while (!q.empty()) {
int now = q.front();
// cout << "now = " << now << endl;
q.pop();
for (auto jh : too[now]) {
if (!viss[pp[jh]]) {
/*
if (!pp[jh]) {
cout << jh << endl;
}
*/
viss[pp[jh]] = true;
ee[jh] = make_pair(now, pp[jh]);
ans++;
q.push(pp[jh]);
}
}
}
return ans;
}
int Main() {
// freopen("a.in", "r", stdin);
read(n);
memset(first, 0xff, sizeof(first));
for (int i = 1, cnt, xx; i < n; ++i) {
read(cnt);
while (cnt--) {
read(xx);
dian[i + n - 1].push_back(xx);
too[xx].push_back(i + n - 1);
if (xx != n) {
add_edge(xx, i + n - 1);
}
}
}
nn = (n - 1) << 1;
S = ++nn, T = ++nn;
for (int i = 1; i < n; ++i) {
add_edge(S, i);
}
for (int i = 1; i < n; ++i) {
add_edge(i + n - 1, T);
}
for (int i = 1; i <= n << 1; ++i) {
first_bak[i] = first[i];
}
int ff = Dinic();
if (ff != n - 1) {
puts("-1");
return 0;
}
// cout << ff << endl;
if (getans() != n - 1) {
puts("-1");
return 0;
}
for (int i = 1; i < n; ++i) {
// assert(ee[i + n - 1].first), assert(ee[i + n - 1].second), assert(ee[i + n - 1].first != ee[i + n - 1].second);
writesp(ee[i + n - 1].first), writeln(ee[i + n - 1].second);
}
return 0;
}
}
int main() {
return dfcmd::Main();
}
Submission Info
| Submission Time | |
|---|---|
| Task | F - Construction of a tree |
| User | pufanyi |
| Language | C++14 (GCC 5.4.1) |
| Score | 2200 |
| Code Size | 21202 Byte |
| Status | AC |
| Exec Time | 954 ms |
| Memory | 32376 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 2200 / 2200 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample01.txt, sample02.txt, sample03.txt |
| All | sample01.txt, sample02.txt, sample03.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in40.txt, in41.txt, in42.txt, in43.txt, in44.txt, in45.txt, in46.txt, in47.txt, in48.txt, in49.txt, in50.txt, in51.txt, in52.txt, in53.txt, in54.txt, in55.txt, in56.txt, in57.txt, in58.txt, in59.txt, in60.txt, in61.txt, in62.txt, in63.txt, in64.txt, in65.txt, in66.txt, in67.txt, sample01.txt, sample02.txt, sample03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| in01.txt | AC | 211 ms | 29440 KiB |
| in02.txt | AC | 62 ms | 15616 KiB |
| in03.txt | AC | 186 ms | 29440 KiB |
| in04.txt | AC | 101 ms | 16256 KiB |
| in05.txt | AC | 197 ms | 27196 KiB |
| in06.txt | AC | 475 ms | 26268 KiB |
| in07.txt | AC | 607 ms | 26376 KiB |
| in08.txt | AC | 694 ms | 26840 KiB |
| in09.txt | AC | 732 ms | 26952 KiB |
| in10.txt | AC | 199 ms | 19328 KiB |
| in11.txt | AC | 196 ms | 19456 KiB |
| in12.txt | AC | 197 ms | 19200 KiB |
| in13.txt | AC | 260 ms | 19712 KiB |
| in14.txt | AC | 250 ms | 19448 KiB |
| in15.txt | AC | 48 ms | 15872 KiB |
| in16.txt | AC | 61 ms | 15872 KiB |
| in17.txt | AC | 86 ms | 16000 KiB |
| in18.txt | AC | 98 ms | 16000 KiB |
| in19.txt | AC | 94 ms | 16128 KiB |
| in20.txt | AC | 49 ms | 32376 KiB |
| in21.txt | AC | 209 ms | 31908 KiB |
| in22.txt | AC | 617 ms | 31808 KiB |
| in23.txt | AC | 165 ms | 19200 KiB |
| in24.txt | AC | 175 ms | 19584 KiB |
| in25.txt | AC | 221 ms | 20212 KiB |
| in26.txt | AC | 197 ms | 19712 KiB |
| in27.txt | AC | 195 ms | 20096 KiB |
| in28.txt | AC | 234 ms | 20212 KiB |
| in29.txt | AC | 143 ms | 19200 KiB |
| in30.txt | AC | 145 ms | 19200 KiB |
| in31.txt | AC | 71 ms | 16000 KiB |
| in32.txt | AC | 75 ms | 16128 KiB |
| in33.txt | AC | 84 ms | 16256 KiB |
| in34.txt | AC | 56 ms | 15872 KiB |
| in35.txt | AC | 81 ms | 16000 KiB |
| in36.txt | AC | 58 ms | 15872 KiB |
| in37.txt | AC | 45 ms | 15744 KiB |
| in38.txt | AC | 56 ms | 15744 KiB |
| in39.txt | AC | 52 ms | 15872 KiB |
| in40.txt | AC | 53 ms | 15744 KiB |
| in41.txt | AC | 432 ms | 26064 KiB |
| in42.txt | AC | 423 ms | 26436 KiB |
| in43.txt | AC | 452 ms | 26852 KiB |
| in44.txt | AC | 458 ms | 26392 KiB |
| in45.txt | AC | 547 ms | 27020 KiB |
| in46.txt | AC | 517 ms | 27016 KiB |
| in47.txt | AC | 447 ms | 26464 KiB |
| in48.txt | AC | 455 ms | 26756 KiB |
| in49.txt | AC | 357 ms | 26972 KiB |
| in50.txt | AC | 375 ms | 27048 KiB |
| in51.txt | AC | 379 ms | 27020 KiB |
| in52.txt | AC | 399 ms | 27032 KiB |
| in53.txt | AC | 378 ms | 27044 KiB |
| in54.txt | AC | 388 ms | 26976 KiB |
| in55.txt | AC | 463 ms | 27068 KiB |
| in56.txt | AC | 386 ms | 27040 KiB |
| in57.txt | AC | 5 ms | 12800 KiB |
| in58.txt | AC | 4 ms | 12544 KiB |
| in59.txt | AC | 200 ms | 29440 KiB |
| in60.txt | AC | 365 ms | 24964 KiB |
| in61.txt | AC | 186 ms | 21504 KiB |
| in62.txt | AC | 519 ms | 29824 KiB |
| in63.txt | AC | 406 ms | 25388 KiB |
| in64.txt | AC | 414 ms | 24996 KiB |
| in65.txt | AC | 710 ms | 25728 KiB |
| in66.txt | AC | 561 ms | 22656 KiB |
| in67.txt | AC | 954 ms | 25088 KiB |
| sample01.txt | AC | 5 ms | 12672 KiB |
| sample02.txt | AC | 5 ms | 12672 KiB |
| sample03.txt | AC | 5 ms | 12800 KiB |