답안 #1009437

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1009437 2024-06-27T14:02:47 Z imarn Drivers (BOI24_drivers) C++14
100 / 100
202 ms 60580 KB
#include<bits/stdc++.h>
//#include "gap.h"
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
using namespace std;
const int mxn=2e5+5;
int pr[mxn];
vector<pii>g[mxn];
bool vis[mxn]{0};
int d[mxn]{0};
int up[mxn][20]{0},dp[mxn][20]{0};
int get(int r){
    return pr[r]==r?r:pr[r]=get(pr[r]);
}
void dfs(int u,int p,int l){
    d[u]=l;up[u][0]=p;vis[u]=1;
    for(int i=1;i<20;i++)up[u][i]=up[up[u][i-1]][i-1];
    for(auto v:g[u]){
        if(vis[v.f])continue;
        dp[v.f][0]=v.s;dfs(v.f,u,l+1);
    }
}
int qr(int a,int b,int res=0){
    if(d[a]>d[b])swap(a,b);
    for(int i=19;i>=0;i--)if(d[b]-(1<<i)>=d[a])res=max(res,dp[b][i]),b=up[b][i];
    if(a==b)return res;
    for(int i=19;i>=0;i--)if(up[a][i]!=up[b][i])res=max({res,dp[a][i],dp[b][i]}),a=up[a][i],b=up[b][i];
    return max({res,dp[a][0],dp[b][0]});
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n,m,q;cin>>n>>m>>q;
    vector<pair<int,pii>>ed;
    for(int i=0;i<m;i++){
        int a,b,c;cin>>a>>b>>c;
        ed.pb({c,{a,b}});
    }sort(ed.begin(),ed.end());iota(pr,pr+n+1,0);
    for(auto it : ed){
        if(get(it.s.f)==get(it.s.s))continue;
        pr[get(it.s.f)]=get(it.s.s);
        g[it.s.f].pb({it.s.s,it.f});g[it.s.s].pb({it.s.f,it.f});
    }
    for(int i=1;i<=n;i++){
        if(vis[i])continue;
        dfs(i,i,0);
    }
    for(int j=1;j<20;j++)for(int i=1;i<=n;i++)dp[i][j]=max(dp[i][j-1],dp[up[i][j-1]][j-1]);
    while(q--){
        int a,b,p;cin>>a>>b>>p;
        if(get(a)!=get(b))cout<<"NE\n";
        else cout<<(qr(a,b)<=p?"TAIP\n":"NE\n");
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 2 ms 8792 KB Output is correct
3 Correct 3 ms 11104 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 49 ms 12068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 2 ms 8536 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 3 ms 8796 KB Output is correct
12 Correct 5 ms 8792 KB Output is correct
13 Correct 3 ms 10932 KB Output is correct
14 Correct 3 ms 10844 KB Output is correct
15 Correct 1 ms 8536 KB Output is correct
16 Correct 1 ms 8536 KB Output is correct
17 Correct 1 ms 8536 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 8 ms 11292 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 2 ms 8540 KB Output is correct
24 Correct 6 ms 11804 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 2 ms 8792 KB Output is correct
3 Correct 3 ms 11104 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 49 ms 12068 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 2 ms 8800 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 3 ms 8796 KB Output is correct
11 Correct 3 ms 10844 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 2 ms 8792 KB Output is correct
3 Correct 3 ms 11104 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 49 ms 12068 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 2 ms 8536 KB Output is correct
13 Correct 2 ms 8792 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 3 ms 8796 KB Output is correct
17 Correct 5 ms 8792 KB Output is correct
18 Correct 3 ms 10932 KB Output is correct
19 Correct 3 ms 10844 KB Output is correct
20 Correct 1 ms 8536 KB Output is correct
21 Correct 1 ms 8536 KB Output is correct
22 Correct 1 ms 8536 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 8 ms 11292 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 2 ms 8796 KB Output is correct
28 Correct 2 ms 8540 KB Output is correct
29 Correct 6 ms 11804 KB Output is correct
30 Correct 1 ms 8540 KB Output is correct
31 Correct 1 ms 8540 KB Output is correct
32 Correct 2 ms 8800 KB Output is correct
33 Correct 2 ms 8796 KB Output is correct
34 Correct 2 ms 8796 KB Output is correct
35 Correct 3 ms 8796 KB Output is correct
36 Correct 3 ms 10844 KB Output is correct
37 Correct 1 ms 8540 KB Output is correct
38 Correct 2 ms 8540 KB Output is correct
39 Correct 1 ms 8540 KB Output is correct
40 Correct 2 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 2 ms 8792 KB Output is correct
3 Correct 3 ms 11104 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 49 ms 12068 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 2 ms 8536 KB Output is correct
13 Correct 2 ms 8792 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 3 ms 8796 KB Output is correct
17 Correct 5 ms 8792 KB Output is correct
18 Correct 3 ms 10932 KB Output is correct
19 Correct 3 ms 10844 KB Output is correct
20 Correct 1 ms 8536 KB Output is correct
21 Correct 1 ms 8536 KB Output is correct
22 Correct 1 ms 8536 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 8 ms 11292 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 2 ms 8796 KB Output is correct
28 Correct 2 ms 8540 KB Output is correct
29 Correct 6 ms 11804 KB Output is correct
30 Correct 1 ms 8540 KB Output is correct
31 Correct 1 ms 8540 KB Output is correct
32 Correct 2 ms 8800 KB Output is correct
33 Correct 2 ms 8796 KB Output is correct
34 Correct 2 ms 8796 KB Output is correct
35 Correct 3 ms 8796 KB Output is correct
36 Correct 3 ms 10844 KB Output is correct
37 Correct 1 ms 8540 KB Output is correct
38 Correct 2 ms 8540 KB Output is correct
39 Correct 1 ms 8540 KB Output is correct
40 Correct 2 ms 8540 KB Output is correct
41 Correct 202 ms 48344 KB Output is correct
42 Correct 14 ms 13656 KB Output is correct
43 Correct 10 ms 11608 KB Output is correct
44 Correct 18 ms 11732 KB Output is correct
45 Correct 13 ms 11464 KB Output is correct
46 Correct 14 ms 13724 KB Output is correct
47 Correct 158 ms 48836 KB Output is correct
48 Correct 11 ms 12120 KB Output is correct
49 Correct 120 ms 60580 KB Output is correct