Submission #737010

# Submission time Handle Problem Language Result Execution time Memory
737010 2023-05-06T12:59:24 Z josanneo22 Paths (BOI18_paths) C++17
100 / 100
167 ms 89104 KB
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second 


void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename A>
void __print(const A &x);
template <typename A, typename B>
void __print(const pair<A, B> &p);
template <typename... A>
void __print(const tuple<A...> &t);
template <typename T>
void __print(stack<T> s);
template <typename T>
void __print(queue<T> q);
template <typename T, typename... U>
void __print(priority_queue<T, U...> q);
template <typename A>
void __print(const A &x) {
    bool first = true;
    cerr << '{';
    for (const auto &i : x) {
        cerr << (first ? "" : ","), __print(i);
        first = false;
    }
    cerr << '}';
}
template <typename A, typename B>
void __print(const pair<A, B> &p) {
    cerr << '(';
    __print(p.first);
    cerr << ',';
    __print(p.second);
    cerr << ')';
}
template <typename... A>
void __print(const tuple<A...> &t) {
    bool first = true;
    cerr << '(';
    apply([&first](const auto &...args) { ((cerr << (first ? "" : ","), __print(args), first = false), ...); }, t);
    cerr << ')';
}
template <typename T>
void __print(stack<T> s) {
    vector<T> debugVector;
    while (!s.empty()) {
        T t = s.top();
        debugVector.push_back(t);
        s.pop();
    }
    reverse(debugVector.begin(), debugVector.end());
    __print(debugVector);
}
template <typename T>
void __print(queue<T> q) {
    vector<T> debugVector;
    while (!q.empty()) {
        T t = q.front();
        debugVector.push_back(t);
        q.pop();
    }
    __print(debugVector);
}
template <typename T, typename... U>
void __print(priority_queue<T, U...> q) {
    vector<T> debugVector;
    while (!q.empty()) {
        T t = q.top();
        debugVector.push_back(t);
        q.pop();
    }
    __print(debugVector);
}
void _print() { cerr << "]\n"; }
template <typename Head, typename... Tail>
void _print(const Head &H, const Tail &...T) {
    __print(H);
    if (sizeof...(T))
        cerr << ", ";
    _print(T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "Line:" << __LINE__ << " [" << #__VA_ARGS__ << "] = ["; _print(__VA_ARGS__)
#else
#define debug(...)
#endif


#define int long long
char buf[1<<23],*p1=buf,*p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline int rd()
{
	int s=0;
	char ch=getchar(),last;
	while(ch<'0'||ch>'9') last=ch,ch=getchar();
	while(ch>='0'&&ch<='9') s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
	return last=='-'?-s:s;
}
int num[100];
inline void rt(int x)
{
	if(x<0) putchar('-'),x=-x;;
	int len=0;
	do num[len++]=x%10;while(x/=10);
	while(len--) putchar(num[len]+'0');
}
const int maxn=3e5+5;
vector<int> c(maxn),a(maxn),b(maxn);
int dp[maxn][32];
void solve(){
    int n=rd(),m=rd(),k=rd();
    for(int i=1;i<=n;i++){
        c[i]=rd();
        c[i]--;
        dp[i][(1<<c[i])]=1;
    }
    for(int i=1;i<=m;i++) a[i]=rd(),b[i]=rd();
    int ans=0;
    for(int bt=1;bt<(1<<k);bt++){
        if(__builtin_popcountll(bt) == 1) {
            continue;
        }
        for(int i=1;i<=m;i++){
            if(bt&(1<<c[a[i]])) dp[a[i]][bt]+=dp[b[i]][bt^(1<<c[a[i]])];
            if(bt&(1<<c[b[i]])) dp[b[i]][bt]+=dp[a[i]][bt^(1<<c[b[i]])];
        }
        for(int i=1;i<=n;i++) ans+=dp[i][bt];
    }
    rt(ans);
}
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	solve();
}

Compilation message

paths.cpp: In function 'long long int rd()':
paths.cpp:115:18: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
  115 |  return last=='-'?-s:s;
      |         ~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7380 KB Output is correct
2 Correct 3 ms 7380 KB Output is correct
3 Correct 4 ms 7400 KB Output is correct
4 Correct 3 ms 7392 KB Output is correct
5 Correct 3 ms 7380 KB Output is correct
6 Correct 3 ms 7380 KB Output is correct
7 Correct 3 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 3 ms 7380 KB Output is correct
10 Correct 3 ms 7404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 10700 KB Output is correct
2 Correct 22 ms 11816 KB Output is correct
3 Correct 89 ms 89036 KB Output is correct
4 Correct 22 ms 20300 KB Output is correct
5 Correct 15 ms 20300 KB Output is correct
6 Correct 68 ms 63620 KB Output is correct
7 Correct 85 ms 89048 KB Output is correct
8 Correct 102 ms 89068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7380 KB Output is correct
2 Correct 3 ms 7380 KB Output is correct
3 Correct 4 ms 7400 KB Output is correct
4 Correct 3 ms 7392 KB Output is correct
5 Correct 3 ms 7380 KB Output is correct
6 Correct 3 ms 7380 KB Output is correct
7 Correct 3 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 3 ms 7380 KB Output is correct
10 Correct 3 ms 7404 KB Output is correct
11 Correct 26 ms 10700 KB Output is correct
12 Correct 22 ms 11816 KB Output is correct
13 Correct 89 ms 89036 KB Output is correct
14 Correct 22 ms 20300 KB Output is correct
15 Correct 15 ms 20300 KB Output is correct
16 Correct 68 ms 63620 KB Output is correct
17 Correct 85 ms 89048 KB Output is correct
18 Correct 102 ms 89068 KB Output is correct
19 Correct 31 ms 13520 KB Output is correct
20 Correct 22 ms 11876 KB Output is correct
21 Correct 105 ms 89056 KB Output is correct
22 Correct 25 ms 20316 KB Output is correct
23 Correct 18 ms 20292 KB Output is correct
24 Correct 66 ms 63624 KB Output is correct
25 Correct 90 ms 88944 KB Output is correct
26 Correct 90 ms 89104 KB Output is correct
27 Correct 49 ms 11860 KB Output is correct
28 Correct 57 ms 14304 KB Output is correct
29 Correct 167 ms 88932 KB Output is correct
30 Correct 138 ms 51092 KB Output is correct
31 Correct 157 ms 50892 KB Output is correct
32 Correct 164 ms 88976 KB Output is correct
33 Correct 3 ms 7380 KB Output is correct
34 Correct 3 ms 7380 KB Output is correct
35 Correct 3 ms 7408 KB Output is correct
36 Correct 3 ms 7380 KB Output is correct
37 Correct 4 ms 7380 KB Output is correct
38 Correct 4 ms 7404 KB Output is correct
39 Correct 4 ms 7380 KB Output is correct
40 Correct 4 ms 7404 KB Output is correct
41 Correct 3 ms 7380 KB Output is correct
42 Correct 3 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7380 KB Output is correct
2 Correct 35 ms 8216 KB Output is correct
3 Correct 10 ms 9004 KB Output is correct
4 Correct 28 ms 35028 KB Output is correct
5 Correct 43 ms 35096 KB Output is correct
6 Correct 96 ms 35132 KB Output is correct
7 Correct 19 ms 8912 KB Output is correct
8 Correct 50 ms 35024 KB Output is correct
9 Correct 42 ms 35156 KB Output is correct
10 Correct 59 ms 35044 KB Output is correct
11 Correct 79 ms 22088 KB Output is correct
12 Correct 79 ms 28756 KB Output is correct
13 Correct 65 ms 22276 KB Output is correct
14 Correct 99 ms 35148 KB Output is correct
15 Correct 115 ms 35140 KB Output is correct
16 Correct 3 ms 7380 KB Output is correct
17 Correct 3 ms 7380 KB Output is correct
18 Correct 3 ms 7308 KB Output is correct
19 Correct 4 ms 7380 KB Output is correct
20 Correct 3 ms 7380 KB Output is correct
21 Correct 3 ms 7380 KB Output is correct
22 Correct 3 ms 7400 KB Output is correct
23 Correct 3 ms 7380 KB Output is correct
24 Correct 3 ms 7400 KB Output is correct
25 Correct 3 ms 7380 KB Output is correct