CF917B.MADMAX

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at games. The game is played on a directed acyclic graph (a DAG) with nn vertices and mm edges. There's a character written on each edge, a lowercase English letter.

Max and Lucas are playing the game. Max goes first, then Lucas, then Max again and so on. Each player has a marble, initially located at some vertex. Each player in his/her turn should move his/her marble along some edge (a player can move the marble from vertex vv to vertex uu if there's an outgoing edge from vv to uu ). If the player moves his/her marble from vertex vv to vertex uu , the "character" of that round is the character written on the edge from vv to uu . There's one additional rule; the ASCII code of character of round ii should be greater than or equal to the ASCII code of character of round i1i-1 (for i>1i>1 ). The rounds are numbered for both players together, i. e. Max goes in odd numbers, Lucas goes in even numbers. The player that can't make a move loses the game. The marbles may be at the same vertex at the same time.

Since the game could take a while and Lucas and Max have to focus on finding Dart, they don't have time to play. So they asked you, if they both play optimally, who wins the game?

You have to determine the winner of the game for all initial positions of the marbles.

输入格式

The first line of input contains two integers nn and mm ( 2<=n<=1002<=n<=100 , ).

The next mm lines contain the edges. Each line contains two integers vv , uu and a lowercase English letter cc , meaning there's an edge from vv to uu written cc on it ( 1<=v,u<=n1<=v,u<=n , vuv≠u ). There's at most one edge between any pair of vertices. It is guaranteed that the graph is acyclic.

输出格式

Print nn lines, a string of length nn in each one. The jj -th character in ii -th line should be 'A' if Max will win the game in case her marble is initially at vertex ii and Lucas's marble is initially at vertex jj , and 'B' otherwise.

输入输出样例

  • 输入#1

    4 4
    1 2 b
    1 3 a
    2 4 c
    3 4 b
    

    输出#1

    BAAA
    ABAA
    BBBA
    BBBB
    
  • 输入#2

    5 8
    5 3 h
    1 2 c
    3 1 c
    3 2 r
    5 1 r
    4 3 z
    5 4 r
    5 2 h
    

    输出#2

    BABBB
    BBBBB
    AABBB
    AAABA
    AAAAB
    

说明/提示

Here's the graph in the first sample test case:

Here's the graph in the second sample test case:

首页