QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#198312#3614. Math TradeZhou_JKAC ✓0ms3864kbC++231.0kb2023-10-03 12:43:372023-10-03 12:43:38

Judging History

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

  • [2023-10-03 12:43:38]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3864kb
  • [2023-10-03 12:43:37]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
using namespace std;
const int N=105;
int n;
int tot;
map<string,int>id;
vector<int>G[N*2];
int deg[N*2];
bool vis[N*2];
int cnt;
bool flag;
void dfs(int u)
{
    vis[u]=true;
    cnt++;
    if(deg[u]!=1) flag=false;
    for(int v:G[u])
    {
        if(vis[v]) continue;
        dfs(v);
    }
    return;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        string name,s,t;
        cin>>name>>s>>t;
        if(!id.count(s)) id[s]=++tot;
        if(!id.count(t)) id[t]=++tot;
        G[id[s]].emplace_back(id[t]);
        G[id[t]].emplace_back(id[s]);
        deg[id[t]]++;
    }
    int ans=0;
    for(int i=1;i<=tot;i++)
        if(!vis[i])
        {
            flag=true;
            cnt=0;
            dfs(i);
            if(flag) ans=max(ans,cnt);
        }
    if(ans==0) cout<<"No trades possible";
    else cout<<ans;
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3632kb

input:

4
Sally Clock Doll
Steve Doll Painting
Carlos Painting Clock
Maria Candlestick Vase

output:

3

result:

ok single line: '3'

Test #2:

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

input:

4
Abby Bottlecap Card
Bob Card Spoon
Chris Spoon Chair
Dan Pencil Pen

output:

No trades possible

result:

ok single line: 'No trades possible'

Test #3:

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

input:

10
P0 I0 I0X
P1 I1 I2
P2 I2 I9
P3 I3 I7
P4 I4 I6
P5 I5 I3
P6 I6 I1
P7 I7 I8
P8 I8 I5
P9 I9 I4

output:

5

result:

ok single line: '5'

Test #4:

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

input:

50
P0 I0 I13
P1 I1 I1X
P2 I2 I48
P3 I3 I41
P4 I4 I22
P5 I5 I10
P6 I6 I2
P7 I7 I35
P8 I8 I15
P9 I9 I12
P10 I10 I5
P11 I11 I49
P12 I12 I0
P13 I13 I32
P14 I14 I37
P15 I15 I16
P16 I16 I28
P17 I17 I40
P18 I18 I23
P19 I19 I4
P20 I20 I14
P21 I21 I3
P22 I22 I46
P23 I23 I8
P24 I24 I18
P25 I25 I19
P26 I26 I26...

output:

45

result:

ok single line: '45'

Test #5:

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

input:

50
P0 I0 I0X
P1 I1 I33
P2 I2 I24
P3 I3 I25
P4 I4 I9
P5 I5 I38
P6 I6 I26
P7 I7 I20
P8 I8 I8X
P9 I9 I42
P10 I10 I18
P11 I11 I30
P12 I12 I34
P13 I13 I32
P14 I14 I21
P15 I15 I28
P16 I16 I15
P17 I17 I47
P18 I18 I13
P19 I19 I37
P20 I20 I6
P21 I21 I5
P22 I22 I16
P23 I23 I41
P24 I24 I10
P25 I25 I19
P26 I26 ...

output:

17

result:

ok single line: '17'

Test #6:

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

input:

50
P0 I0 I4
P1 I1 I27
P2 I2 I44
P3 I3 I31
P4 I4 I40
P5 I5 I45
P6 I6 I0
P7 I7 I42
P8 I8 I13
P9 I9 I32
P10 I10 I38
P11 I11 I21
P12 I12 I17
P13 I13 I10
P14 I14 I20
P15 I15 I30
P16 I16 I36
P17 I17 I39
P18 I18 I11
P19 I19 I12
P20 I20 I24
P21 I21 I14
P22 I22 I47
P23 I23 I35
P24 I24 I29
P25 I25 I37
P26 I26...

output:

34

result:

ok single line: '34'

Test #7:

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

input:

50
P0 I0 I18
P1 I1 I22
P2 I2 I31
P3 I3 I36
P4 I4 I39
P5 I5 I44
P6 I6 I17
P7 I7 I19
P8 I8 I43
P9 I9 I25
P10 I10 I23
P11 I11 I29
P12 I12 I8
P13 I13 I14
P14 I14 I10
P15 I15 I6
P16 I16 I26
P17 I17 I35
P18 I18 I49
P19 I19 I27
P20 I20 I1
P21 I21 I45
P22 I22 I46
P23 I23 I0
P24 I24 I12
P25 I25 I11
P26 I26 I...

output:

24

result:

ok single line: '24'

Test #8:

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

input:

50
P0 I0 I28
P1 I1 I13
P2 I2 I4
P3 I3 I3X
P4 I4 I25
P5 I5 I39
P6 I6 I36
P7 I7 I44
P8 I8 I2
P9 I9 I22
P10 I10 I14
P11 I11 I10
P12 I12 I47
P13 I13 I34
P14 I14 I49
P15 I15 I38
P16 I16 I16X
P17 I17 I24
P18 I18 I41
P19 I19 I27
P20 I20 I15
P21 I21 I26
P22 I22 I46
P23 I23 I1
P24 I24 I48
P25 I25 I32
P26 I26...

output:

35

result:

ok single line: '35'

Test #9:

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

input:

100
P0 I0 I20
P1 I1 I67
P2 I2 I4
P3 I3 I63
P4 I4 I33
P5 I5 I38
P6 I6 I91
P7 I7 I93
P8 I8 I79
P9 I9 I27
P10 I10 I32
P11 I11 I72
P12 I12 I65
P13 I13 I16
P14 I14 I10
P15 I15 I85
P16 I16 I77
P17 I17 I26
P18 I18 I11
P19 I19 I5
P20 I20 I52
P21 I21 I74
P22 I22 I82
P23 I23 I30
P24 I24 I6
P25 I25 I71
P26 I26...

output:

45

result:

ok single line: '45'

Test #10:

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

input:

100
P0 I0 I64
P1 I1 I46
P2 I2 I54
P3 I3 I9
P4 I4 I32
P5 I5 I84
P6 I6 I94
P7 I7 I78
P8 I8 I2
P9 I9 I34
P10 I10 I45
P11 I11 I52
P12 I12 I31
P13 I13 I57
P14 I14 I70
P15 I15 I44
P16 I16 I66
P17 I17 I16
P18 I18 I62
P19 I19 I56
P20 I20 I97
P21 I21 I4
P22 I22 I77
P23 I23 I20
P24 I24 I12
P25 I25 I65
P26 I26...

output:

69

result:

ok single line: '69'

Test #11:

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

input:

100
P0 I0 I60
P1 I1 I42
P2 I2 I4
P3 I3 I58
P4 I4 I81
P5 I5 I74
P6 I6 I82
P7 I7 I20
P8 I8 I10
P9 I9 I70
P10 I10 I0
P11 I11 I55
P12 I12 I3
P13 I13 I8
P14 I14 I18
P15 I15 I63
P16 I16 I56
P17 I17 I15
P18 I18 I72
P19 I19 I52
P20 I20 I53
P21 I21 I85
P22 I22 I87
P23 I23 I77
P24 I24 I22
P25 I25 I97
P26 I26 ...

output:

24

result:

ok single line: '24'

Test #12:

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

input:

100
P0 I0 I67
P1 I1 I8
P2 I2 I18
P3 I3 I4
P4 I4 I6
P5 I5 I33
P6 I6 I24
P7 I7 I29
P8 I8 I86
P9 I9 I44
P10 I10 I77
P11 I11 I66
P12 I12 I61
P13 I13 I45
P14 I14 I65
P15 I15 I52
P16 I16 I34
P17 I17 I35
P18 I18 I15
P19 I19 I22
P20 I20 I5
P21 I21 I26
P22 I22 I80
P23 I23 I69
P24 I24 I94
P25 I25 I99
P26 I26 ...

output:

75

result:

ok single line: '75'

Test #13:

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

input:

100
P0 I0 I32
P1 I1 I56
P2 I2 I39
P3 I3 I96
P4 I4 I72
P5 I5 I91
P6 I6 I27
P7 I7 I5
P8 I8 I64
P9 I9 I15
P10 I10 I73
P11 I11 I53
P12 I12 I18
P13 I13 I29
P14 I14 I68
P15 I15 I49
P16 I16 I28
P17 I17 I85
P18 I18 I63
P19 I19 I89
P20 I20 I97
P21 I21 I46
P22 I22 I69
P23 I23 I66
P24 I24 I79
P25 I25 I80
P26 I...

output:

45

result:

ok single line: '45'

Test #14:

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

input:

10
P1 I1 I2
P2 I2 I3
P3 I3 I4
P4 I4 I5
P5 I5 I6
P6 I6 I7
P7 I7 I8
P8 I8 I9
P9 I9 I10
P10 I10 I1

output:

10

result:

ok single line: '10'

Test #15:

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

input:

10
P1 I1 I2
P2 I2 I3
P3 I3 I4
P4 I4 I5
P5 I5 I1
P6 I6 I7
P7 I7 I8
P8 I8 I9
P9 I9 I10
P10 I10 I6

output:

5

result:

ok single line: '5'

Test #16:

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

input:

9
P1 I1 I2
P2 I2 I3
P3 I3 I1
P4 I4 I5
P5 I5 I6
P6 I6 I4
P7 I7 I8
P8 I8 I9
P9 I9 I7

output:

3

result:

ok single line: '3'

Test #17:

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

input:

14
P1 I1 I2
P2 I2 I1
P3 I3 I4
P4 I4 I5
P5 I5 I3
P6 I6 I7
P7 I7 I8
P8 I8 I9
P9 I9 I6
P10 I10 I11
P11 I11 I12
P12 I12 I13
P13 I13 I14
P14 I14 I10

output:

5

result:

ok single line: '5'

Test #18:

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

input:

7
P1 I1 I2
P2 I2 I3
P3 I3 I4
P4 I4 I1
P5 I5 I6
P6 I6 I7
P7 I7 I5

output:

4

result:

ok single line: '4'

Test #19:

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

input:

7
P7 I7 I5
P2 I2 I3
P3 I3 I4
P6 I6 I7
P4 I4 I1
P5 I5 I6
P1 I1 I2

output:

4

result:

ok single line: '4'

Test #20:

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

input:

6
P1 I1 I2
P2 I2 I3
P3 I3 I4
P4 I4 I5
P5 I6 I7
P6 I7 I6

output:

2

result:

ok single line: '2'

Test #21:

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

input:

4
P1 I1 I2
P2 I3 I4
P3 I5 I6
P4 I7 I8

output:

No trades possible

result:

ok single line: 'No trades possible'

Test #22:

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

input:

10
P1 I1 I2
P2 I2 I3
P3 I3 I4
P4 I4 I5
P5 I5 I6
P6 I6 I7
P7 I7 I8
P8 I8 I9
P9 I9 I10
P10 I10 I11

output:

No trades possible

result:

ok single line: 'No trades possible'

Test #23:

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

input:

10
P0 I0 I1
P1 I1 I8
P2 I2 I6
P3 I3 I9
P4 I4 I2
P5 I5 I7
P6 I6 I3
P7 I7 I4
P8 I8 I0
P9 I9 I5

output:

7

result:

ok single line: '7'

Test #24:

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

input:

10
P0 I0 I5
P1 I1 I3
P2 I2 I8
P3 I3 I9
P4 I4 I1
P5 I5 I6
P6 I6 I7
P7 I7 I4
P8 I8 I2
P9 I9 I0

output:

8

result:

ok single line: '8'

Test #25:

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

input:

10
P0 I0 I6
P1 I1 I2
P2 I2 I8
P3 I3 I4
P4 I4 I3
P5 I5 I0
P6 I6 I5
P7 I7 I7X
P8 I8 I1
P9 I9 I9X

output:

3

result:

ok single line: '3'