Submission #00027
ソースコード
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 | #include<bits/stdc++.h> using namespace std; int n,a; int flg[502]={}; int rt[502]; int can_cnt[502]={}; vector< int >edge[502]; vector< int >can[502]; int finish=0,none=0; int dfs( int ); int main(){ cin>>n; for ( int i=0;i<n-1;i++){ for ( int j=0;j<n-1;j++){ cin>>a; if (a){ edge[j].push_back(i); can_cnt[j]++; can[i].push_back(j); } } } dfs(0); if (!finish || none)cout<< "no" <<endl; return (0); } int dfs( int now){ if (finish || none) return (0); if (now==n-1){ finish=1; cout<< "yes" <<endl; for ( int i=0;i<n-1;i++){ cout<<rt[i]+1<<endl; } return (0); } if (edge[now].size()==0){none=1; return (0);} for ( int i=0;i<edge[now].size();i++){ int next = edge[now][i]; int f=0; for ( int j=0;j<can[next].size();j++){ int dd = can[next][j]; if (now<dd && can_cnt[dd]==1){f=1; break ;} } if (flg[next]==0 && !f && !finish && !none){ for ( int j=0;j<can[next].size();j++)can_cnt[can[next][j]]--; flg[next]=1;rt[now]=next; dfs(now+1); flg[next]=0; for ( int j=0;j<can[next].size();j++)can_cnt[can[next][j]]++; } } return (0); } |
ステータス
項目 | データ |
---|---|
問題 | 0010 - あみだくじ |
ユーザー名 | Doll |
投稿日時 | 2017-10-24 18:34:40 |
言語 | C++11 |
状態 | Accepted |
得点 | 16 |
ソースコード長 | 1207 Byte |
最大実行時間 | 1319 ms |
最大メモリ使用量 | 864 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 16 / 16 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in01.txt | AC | 17 ms | 480 KB |
1
|
in02.txt | AC | 14 ms | 428 KB |
1
|
in03.txt | AC | 19 ms | 508 KB |
1
|
in04.txt | AC | 15 ms | 456 KB |
1
|
in05.txt | AC | 20 ms | 532 KB |
1
|
in06.txt | AC | 16 ms | 596 KB |
1
|
in07.txt | AC | 14 ms | 664 KB |
1
|
in08.txt | AC | 17 ms | 596 KB |
1
|
in09.txt | AC | 19 ms | 652 KB |
1
|
in10.txt | AC | 19 ms | 560 KB |
1
|
in11.txt | AC | 22 ms | 700 KB |
1
|
in12.txt | AC | 25 ms | 816 KB |
1
|
in13.txt | AC | 19 ms | 652 KB |
1
|
in14.txt | AC | 17 ms | 724 KB |
1
|
in15.txt | AC | 49 ms | 800 KB |
1
|
in16.txt | AC | 22 ms | 864 KB |
1
|
in17.txt | AC | 34 ms | 804 KB |
1
|
in18.txt | AC | 23 ms | 740 KB |
1
|
in19.txt | AC | 25 ms | 676 KB |
1
|
in20.txt | AC | 21 ms | 740 KB |
1
|
in21.txt | AC | 20 ms | 680 KB |
1
|
in22.txt | AC | 18 ms | 628 KB |
1
|
in23.txt | AC | 1319 ms | 832 KB |
1
|
in24.txt | AC | 15 ms | 616 KB |
1
|