无敌了,短短几行代码就让我tle了
查看原帖
无敌了,短短几行代码就让我tle了
311306
dk_qwq楼主2024/10/2 20:25
#include<iostream>
#include<cstdio>
#include<vector>
#define pb push_back
using namespace std;
// namespace INPUT{
//     char buf[1<<20],*p1,*p2;
//     #define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
// }
// using namespace INPUT;
// template<typename T>
// T read(){
//     char ch=gc();
//     T x=0,p=1;
//     while(ch<'0'||ch>'9'){
//         if(ch=='-') p=-1;
//         ch=gc();
//     }
//     while(ch<='9'&&ch>='0'){
//         x=(x<<3)+(x<<1)+(ch^48);
//         ch=gc();
//     }
//     return x*p;
// }
const int N=1e5+5;
vector<int>G[N];
void add(int u,int v){G[u].pb(v),G[v].pb(u);}
int dep[N];
void dfs(int u,int fa){
    dep[u]=dep[fa]+1;
    for(auto v:G[u])
        if(v!=fa) dfs(v,u);
}
int n,root;
int q;
int z,p;
int main(){
    // freopen("F.in","r",stdin);
    // freopen("F.out","w",stdout);
    cin>>n>>root;
    // n=read<int>(),root=read<int>();
    for(int i=1;i<n;i++) {
        int a,b;
        cin>>a>>b;
        // add(a,b);
        // add(read<int>(),read<int>());
    }
    // dfs(root,0);
    // q=read<int>();
    cin>>q;
    while(q--){
        // z=read<int>(),p=read<int>();
        cin>>z>>p;
        // if(n==1) {
        //     cout<<0<<endl;continue;
        // }
        // if(z==root) {
        //     cout<<1<<endl;continue;
        // }
        if(p==0) {
            cout<<-1<<endl;continue;
        }
        int ans=0;
        // int ans=(dep[z]+p-2)/p;
        // if(G[root].size()>1) ans++;
        cout<<ans<<endl;
    }
}
2024/10/2 20:25
加载中...