QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#791180#1401. Making Friends is Funmodwwe0 2ms10016kbC++234.0kb2024-11-28 17:19:272024-11-28 17:19:31

Judging History

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

  • [2024-11-28 17:19:31]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:10016kb
  • [2024-11-28 17:19:27]
  • 提交

answer

#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC optimize("conserve-stack")
#include<bits/stdc++.h>
#define int  long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define mask(k) (1<<k)
#define mp make_pair
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
#define getchar_unlocked getchar

inline int scan()
{
    char c = getchar_unlocked();
    int x = 0;
    while (c < '0' || c > '9')
    {
        c = getchar_unlocked();
    }
    while (c >= '0' && c <= '9')
    {
        x = (x << 1) + (x << 3) + c - '0';
        c = getchar_unlocked();
    }
    return x;
}
void phongbeo();
const int inf = 1e9;
const ll mod2 = 1e9 + 7;
const int  mod1 = 998244353;
const ll base=67;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int add(int x,int y)
{
    if(x+y>=mod2) x-=mod2;
    if(x+y<0)x+=mod2;
    return x+y;
}
struct icd
{
    long double a;
    int b;
};
struct ib
{
    int a;
    int b;
};
struct ic
{
    int a, b, c;
};
struct id
{
    int a, b, c, d;
};
struct ie
{
    int a, b, c, d, e;

};
int n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, mid, l2, r2, center;
int  i, s10, s12,k1,k2,k3,s11,t,lim,w,l,r ;
int kk;
int el = 19;
main()
{
    if(fopen(task".inp","r"))
    {
        fin(task);
        fou(task);
    }
    NHP
    /// cin>>s1;
    // modwwe
    phongbeo();
    // checktime
}
int c[100001];
bool b[100001];
vector<int> v[100001];
struct skibidi
{
    ib dsu[100001];
    vector<int> cc[100001];
    void reset()
    {
        for(int i=1; i<=n; i++)
            dsu[i]= {1,i},cc[i].pb({i});
    }
    int get(int x)
    {
        if(dsu[x].b==x) return x;
        return dsu[x].b=get(dsu[x].b);
    }
    void noi(int x,int y)
    {
        x=get(x);
        y=get(y);
        if(x==y) return;
        if(dsu[x].a<dsu[y].a)swap(x,y);
        dsu[x].a+=dsu[y].a;
        dsu[y].b=x;
        for(auto f:cc[y])
            cc[x].pb(f);
        vector<int>().swap(cc[y]);
    }
} ds;
map<pair<int,int>,bool>cnt;
void phongbeo()
{
    cin>>n>>m;
    /// kieu ko tim du 2 con thi ko noi dc
    stack<ib> s;
    for(int i=1; i<=m; i++)
    {
        cin>>l>>r;
        c[l]++;
        v[l].pb(r);
        cnt[ {l,r}]=1;
    }
    for(int i=1; i<=n; i++)
        if(c[i]>=2)
            s.push({i,v[i][0]}),b[i]=1;
    ds.reset();
    while(!s.empty())
    {
        ib x=s.top();
        s.pop();
        int hihi=ds.get(x.a);
        if(ds.dsu[hihi].a!=1)ds.noi(x.b,x.a);
        for(auto f:v[x.a])
        {
            ds.noi(f,x.b);
            if(b[x.b]&&v[x.b].size()>0)ds.noi(f,v[x.b][0]);
        }
        for(auto f:v[x.a])
        {
            if(ds.dsu[ds.get(f)].a>=3&&!b[f])
            {
                b[f]=1;
                s.push({f,ds.get(f)});
            }
            else if(!b[f])
            {
                for(auto g:ds.cc[ds.get(f)])
                {
                    if(g!=f&&cnt[ {f,g}]==0)
                    {
                        c[f]++;
                        if(c[f]>=2)
                        {
                            b[f]=1;
                            s.push({f,ds.get(f)});
                            break;
                        }
                    }
                }

            }
        }
    }
    for(int i=1; i<=n; i++)
    {
        if(ds.dsu[i].b==i)
        {
            s4+=ds.dsu[i].a*(ds.dsu[i].a-1);
        }
        for(auto x:v[i])
            if(ds.get(x)!=ds.get(i))
                s4++;
    }
    cout<<s4;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 0ms
memory: 7760kb

input:

1 0

output:

0

result:

ok single line: '0'

Test #2:

score: 5
Accepted
time: 0ms
memory: 7904kb

input:

2 1
2 1

output:

1

result:

ok single line: '1'

Test #3:

score: 5
Accepted
time: 1ms
memory: 9712kb

input:

3 2
2 1
2 3

output:

4

result:

ok single line: '4'

Test #4:

score: 5
Accepted
time: 1ms
memory: 9736kb

input:

13 12
1 2
2 3
3 4
1 5
5 6
6 7
7 8
8 9
9 10
11 1
12 11
13 11

output:

77

result:

ok single line: '77'

Test #5:

score: 5
Accepted
time: 1ms
memory: 10012kb

input:

100 100
78 82
67 85
2 22
88 36
16 50
78 11
53 64
7 68
71 48
27 94
82 22
9 57
35 65
78 70
81 86
22 42
37 19
50 64
98 70
78 31
62 41
33 9
7 100
57 13
71 93
93 15
50 46
66 36
64 62
70 79
17 57
81 74
98 87
62 19
56 10
2 7
10 71
14 25
1 47
39 75
96 3
22 50
57 53
56 30
92 11
58 90
87 99
65 90
85 95
100 25...

output:

3121

result:

ok single line: '3121'

Test #6:

score: 5
Accepted
time: 1ms
memory: 9776kb

input:

99 33
27 26
97 35
83 28
71 76
49 75
55 35
1 83
85 70
68 2
49 69
4 46
22 51
38 52
87 21
87 27
82 46
91 88
49 61
25 7
6 99
77 83
62 36
65 33
29 16
64 54
63 70
14 95
69 80
58 87
85 60
45 71
45 78
11 44

output:

56

result:

ok single line: '56'

Test #7:

score: 5
Accepted
time: 1ms
memory: 8156kb

input:

100 300
32 54
22 81
16 72
62 15
41 2
5 81
55 54
33 36
40 42
56 25
98 64
60 52
17 25
46 78
71 32
52 15
84 36
11 50
91 2
54 30
71 84
49 83
78 69
86 22
52 98
57 56
48 40
16 19
16 22
56 35
58 94
4 57
16 25
65 61
98 69
47 69
44 86
17 36
64 42
64 97
100 61
57 81
65 87
81 87
79 12
31 90
3 85
51 34
81 1
40 ...

output:

9514

result:

ok single line: '9514'

Test #8:

score: 5
Accepted
time: 0ms
memory: 10016kb

input:

100 3000
57 50
4 36
78 39
65 50
48 86
11 90
16 47
72 92
37 19
58 19
14 64
83 9
12 59
69 38
20 75
42 88
5 84
6 98
62 31
82 1
67 80
52 17
77 55
60 81
25 49
45 78
28 10
32 77
57 21
53 62
1 40
75 97
21 37
8 38
7 22
11 83
85 56
90 53
93 8
41 34
44 25
66 42
20 82
35 69
24 21
45 54
66 93
35 96
8 94
45 71
2...

output:

9900

result:

ok single line: '9900'

Test #9:

score: 5
Accepted
time: 2ms
memory: 7760kb

input:

100 1000
35 88
50 96
81 11
64 100
99 52
25 78
36 68
34 52
20 9
61 76
71 11
64 41
51 74
2 78
78 86
29 70
44 34
83 9
94 92
60 29
33 95
19 91
33 1
55 78
81 35
36 22
17 90
73 5
40 68
44 86
7 98
56 66
29 17
4 36
15 34
39 97
95 68
94 98
46 45
43 3
32 23
60 79
81 86
83 46
52 37
15 83
56 32
79 47
9 39
24 73...

output:

9900

result:

ok single line: '9900'

Test #10:

score: 5
Accepted
time: 1ms
memory: 6112kb

input:

100 300
13 32
15 27
98 61
4 41
95 39
83 61
7 12
48 67
86 6
79 96
15 74
68 11
1 6
25 1
74 1
8 38
62 100
69 28
40 72
32 26
59 87
13 45
19 29
54 22
90 67
70 96
49 98
24 14
56 35
89 59
1 81
44 26
45 92
68 65
52 78
58 25
50 74
97 66
23 100
58 22
48 94
86 44
86 3
35 19
77 12
65 68
21 63
95 87
15 29
6 23
4...

output:

9514

result:

ok single line: '9514'

Test #11:

score: 5
Accepted
time: 1ms
memory: 7780kb

input:

100 120
10 95
23 51
4 41
37 69
26 97
24 92
3 52
39 7
29 50
6 69
99 3
20 30
74 55
2 68
88 83
1 54
32 90
58 65
62 35
63 58
8 6
33 61
56 32
91 64
72 86
89 15
12 61
53 46
34 63
7 38
30 40
92 98
67 25
36 57
51 67
10 65
37 97
21 46
58 59
31 47
82 51
38 24
29 88
5 58
82 62
59 86
74 95
28 68
96 85
21 33
86 ...

output:

5143

result:

ok single line: '5143'

Test #12:

score: 5
Accepted
time: 1ms
memory: 7796kb

input:

100 100
7 8
86 87
74 75
92 93
94 95
40 41
18 19
54 55
100 1
80 81
89 90
6 7
76 77
51 52
11 12
25 26
28 29
27 28
36 37
17 18
29 30
14 15
97 98
96 97
55 56
33 34
72 73
48 49
99 100
45 46
83 84
46 47
15 16
22 23
69 70
8 9
71 72
87 88
65 66
58 59
12 13
68 69
16 17
37 38
73 74
62 63
50 51
23 24
38 39
77 ...

output:

100

result:

ok single line: '100'

Test #13:

score: 5
Accepted
time: 1ms
memory: 9788kb

input:

100 101
7 8
86 87
74 75
92 93
94 95
40 41
18 19
54 55
100 1
80 81
89 90
6 7
76 77
51 52
11 12
25 26
28 29
27 28
36 37
17 18
29 30
14 15
97 98
96 97
55 56
33 34
72 73
48 49
99 100
45 46
83 84
46 47
15 16
22 23
69 70
8 9
71 72
87 88
65 66
58 59
12 13
68 69
16 17
37 38
73 74
62 63
50 51
23 24
38 39
77 ...

output:

9900

result:

ok single line: '9900'

Test #14:

score: 0
Wrong Answer
time: 0ms
memory: 9664kb

input:

100 99
27 46
25 82
1 17
56 78
9 59
18 19
2 5
4 48
25 54
5 8
49 83
40 93
15 30
14 71
15 73
31 60
36 39
14 77
4 35
25 72
32 97
8 12
2 11
1 6
6 87
1 96
1 43
48 50
22 26
15 36
9 25
3 34
39 58
25 70
13 69
12 24
20 49
17 100
15 51
2 7
47 62
15 28
81 85
12 23
33 84
18 22
50 76
54 91
26 64
21 42
12 20
8 55
...

output:

1029

result:

wrong answer 1st lines differ - expected: '9709', found: '1029'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%