Submission #888342

# Submission time Handle Problem Language Result Execution time Memory
888342 2023-12-17T02:09:18 Z 1075508020060209tc Paths (BOI18_paths) C++14
100 / 100
2716 ms 59692 KB
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define int long long
//const int mod=998244353;
int n;int m;int K;
int cr[500005];
int ar[500005];
int br[500005];
vector<int>e[500005];
int ans;

void solve2(){
for(int i=1;i<=m;i++){
    if(cr[ar[i]]!=cr[br[i]]){ans+=2;}
}
}

void solve3(){
int ret=0;
for(int nw=1;nw<=n;nw++){
    vector<int>tbl(10,0);
    for(int i=0;i<e[nw].size();i++){
        int v=e[nw][i];
        for(int j=1;j<=5;j++){
            if(j==cr[v]){continue;}
            if(j==cr[nw]){continue;}
            if(cr[v]==cr[nw]){continue;}
            ret+=tbl[j];
        }
        tbl[cr[v]]++;
    }
}
ret*=2;
ans+=ret;
}

void solve4(){
vector<vector<int>>tbl(n+10,vector<int>(6,0));
for(int nw=1;nw<=n;nw++){
    for(int i=0;i<e[nw].size();i++){
        int v=e[nw][i];
        if(cr[v]!=cr[nw]){
            tbl[nw][cr[v]]++;
        }
    }
}
for(int i=1;i<=m;i++){
    int a=ar[i];int b=br[i];
    for(int x=1;x<=5;x++){
        for(int y=1;y<=5;y++){
            if(x==cr[a]||y==cr[a]||x==cr[b]||y==cr[b]||x==y||cr[a]==cr[b]){continue;}
            ans+=tbl[a][x]*tbl[b][y]*2;
        }
    }

}


}

void solve5(){
vector<vector<int>>tbl(n+10,vector<int>(6,0));
for(int nw=1;nw<=n;nw++){
    for(int i=0;i<e[nw].size();i++){
        int v=e[nw][i];
        if(cr[v]!=cr[nw]){
            tbl[nw][cr[v]]++;
        }
    }
}
for(int mid=1;mid<=n;mid++){
    vector<vector<int>>tbl2(6,vector<int>(6,0));
    for(int i=0;i<e[mid].size();i++){
        int nw=e[mid][i];
        if(cr[nw]==cr[mid]){continue;}
        
      //  st.insert(cr[nw]);
        //st.insert(cr[mid]);
        for(int b=1;b<=5;b++){
            for(int x=1;x<=5;x++){
                for(int y=1;y<=5;y++){
                    set<int>st;
                    st.insert(cr[nw]);
                    st.insert(cr[mid]);
                    st.insert(b);
                    st.insert(x);
                    st.insert(y);
                    if(st.size()==5){
                        ans+=tbl[nw][b]*tbl2[x][y]*2;
                    }
                }
            }
        }
        for(int b=1;b<=5;b++){
            tbl2[cr[nw]][b]+=tbl[nw][b];
        }
    }
}



}


signed main(){
cin>>n>>m>>K;
for(int i=1;i<=n;i++){
    cin>>cr[i];
}
for(int i=1;i<=m;i++){
    cin>>ar[i]>>br[i];
    e[ar[i]].push_back(br[i]);
    e[br[i]].push_back(ar[i]);
}
ans=0;
solve2();
solve3();
//cout<<ans<<" ";
if(K>=4){solve4();}
if(K==5){solve5(); }
cout<<ans<<"\n";


}

Compilation message

paths.cpp: In function 'void solve3()':
paths.cpp:23:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i=0;i<e[nw].size();i++){
      |                 ~^~~~~~~~~~~~~
paths.cpp: In function 'void solve4()':
paths.cpp:41:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i=0;i<e[nw].size();i++){
      |                 ~^~~~~~~~~~~~~
paths.cpp: In function 'void solve5()':
paths.cpp:65:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     for(int i=0;i<e[nw].size();i++){
      |                 ~^~~~~~~~~~~~~
paths.cpp:74:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     for(int i=0;i<e[mid].size();i++){
      |                 ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 16988 KB Output is correct
2 Correct 4 ms 16984 KB Output is correct
3 Correct 4 ms 16984 KB Output is correct
4 Correct 4 ms 16988 KB Output is correct
5 Correct 4 ms 16988 KB Output is correct
6 Correct 4 ms 16988 KB Output is correct
7 Correct 4 ms 16988 KB Output is correct
8 Correct 5 ms 16984 KB Output is correct
9 Correct 4 ms 16988 KB Output is correct
10 Correct 4 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 28244 KB Output is correct
2 Correct 101 ms 27996 KB Output is correct
3 Correct 253 ms 33576 KB Output is correct
4 Correct 148 ms 29012 KB Output is correct
5 Correct 148 ms 29328 KB Output is correct
6 Correct 206 ms 31932 KB Output is correct
7 Correct 280 ms 33620 KB Output is correct
8 Correct 327 ms 34156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 16988 KB Output is correct
2 Correct 4 ms 16984 KB Output is correct
3 Correct 4 ms 16984 KB Output is correct
4 Correct 4 ms 16988 KB Output is correct
5 Correct 4 ms 16988 KB Output is correct
6 Correct 4 ms 16988 KB Output is correct
7 Correct 4 ms 16988 KB Output is correct
8 Correct 5 ms 16984 KB Output is correct
9 Correct 4 ms 16988 KB Output is correct
10 Correct 4 ms 16988 KB Output is correct
11 Correct 117 ms 28244 KB Output is correct
12 Correct 101 ms 27996 KB Output is correct
13 Correct 253 ms 33576 KB Output is correct
14 Correct 148 ms 29012 KB Output is correct
15 Correct 148 ms 29328 KB Output is correct
16 Correct 206 ms 31932 KB Output is correct
17 Correct 280 ms 33620 KB Output is correct
18 Correct 327 ms 34156 KB Output is correct
19 Correct 121 ms 28244 KB Output is correct
20 Correct 99 ms 27984 KB Output is correct
21 Correct 250 ms 33892 KB Output is correct
22 Correct 146 ms 29264 KB Output is correct
23 Correct 140 ms 29200 KB Output is correct
24 Correct 213 ms 31808 KB Output is correct
25 Correct 239 ms 33684 KB Output is correct
26 Correct 258 ms 34128 KB Output is correct
27 Correct 125 ms 28240 KB Output is correct
28 Correct 143 ms 29680 KB Output is correct
29 Correct 342 ms 59420 KB Output is correct
30 Correct 254 ms 44744 KB Output is correct
31 Correct 247 ms 44872 KB Output is correct
32 Correct 388 ms 59692 KB Output is correct
33 Correct 4 ms 16988 KB Output is correct
34 Correct 4 ms 16984 KB Output is correct
35 Correct 4 ms 16988 KB Output is correct
36 Correct 4 ms 16988 KB Output is correct
37 Correct 4 ms 16988 KB Output is correct
38 Correct 4 ms 16988 KB Output is correct
39 Correct 4 ms 16988 KB Output is correct
40 Correct 4 ms 16988 KB Output is correct
41 Correct 4 ms 16988 KB Output is correct
42 Correct 4 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 16988 KB Output is correct
2 Correct 2183 ms 21240 KB Output is correct
3 Correct 36 ms 21940 KB Output is correct
4 Correct 71 ms 23868 KB Output is correct
5 Correct 70 ms 24148 KB Output is correct
6 Correct 2290 ms 32532 KB Output is correct
7 Correct 40 ms 21840 KB Output is correct
8 Correct 90 ms 32336 KB Output is correct
9 Correct 96 ms 32712 KB Output is correct
10 Correct 84 ms 32492 KB Output is correct
11 Correct 1973 ms 25032 KB Output is correct
12 Correct 2716 ms 29780 KB Output is correct
13 Correct 2335 ms 27204 KB Output is correct
14 Correct 2308 ms 32532 KB Output is correct
15 Correct 2529 ms 32604 KB Output is correct
16 Correct 4 ms 17016 KB Output is correct
17 Correct 4 ms 16988 KB Output is correct
18 Correct 4 ms 16984 KB Output is correct
19 Correct 4 ms 16988 KB Output is correct
20 Correct 4 ms 16988 KB Output is correct
21 Correct 4 ms 16988 KB Output is correct
22 Correct 4 ms 16988 KB Output is correct
23 Correct 4 ms 16988 KB Output is correct
24 Correct 4 ms 16988 KB Output is correct
25 Correct 4 ms 16988 KB Output is correct