This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL)
#define sz(x) (int)((x).size())
#define pb push_back
#define vi vector<int>
#define vb vector<bool>
#define vvb vector<vb>
#define pi pair<int,int>
#define vpi vector<pi>
#define vvi vector<vi>
#define vc vector<char>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pbb() pop_back()
#define f first
#define s second
#define ll long long
#define int long long
#define ull unsigned long long
#define forr(i, a, b) for(int i=a; i<b; i++)
const int N=4000+1, mod=1e9 + 9, inf=1e27+1;
using namespace std;
//vi dx= { 0, 1, 0 , -1} , dy= {-1,0, 1, 0};
int cnt[N];
bool dp[N][N];
void task()
{
int n, k;
cin>>n>>k;
forr(i, 1, n+1)
{
cnt[i]=1;
forr(j, 0, n+1) dp[i][j]=0;
dp[i][i]=1;
}
forr(i, 0, n+k-1)
{
char ch;
int a, b;
cin>>ch;
if(ch=='S')
{
cin>>a>>b;
forr(i, 1, n+1)
{
if(dp[a][i] and !dp[b][i])
{
cnt[i]++;
dp[b][i]=1;
}
swap(a,b);
if(dp[a][i] and !dp[b][i])
{
cnt[i]++;
dp[b][i]=1;
}
}
}
else if(ch=='Q')
{
cin>>a>>b;
if(dp[a][b]) cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
else{
cin>>a;
cout<<cnt[a]<<endl;
}
}
}
signed main()
{
fast;
int t;
t=1;
//cin>>t;
while(t--) task();
}
Compilation message (stderr)
servers.cpp:21:42: warning: overflow in conversion from 'double' to 'long long int' changes value from '1.0e+27' to '9223372036854775807' [-Woverflow]
21 | const int N=4000+1, mod=1e9 + 9, inf=1e27+1;
| ~~~~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |