답안 #984582

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
984582 2024-05-16T19:53:41 Z Mr_Ph 자매 도시 (APIO20_swap) C++17
0 / 100
82 ms 23856 KB
#include "swap.h"

#include <bits/stdc++.h>
// #include "grader.cpp"
using namespace std;
vector<vector<pair<int,int>>>adj;
int mx=0,n=0;
void init(int N, int m,std::vector<int> u, std::vector<int> v, std::vector<int> w) {
    adj.resize(N+1);
    for(int i=0;i<m;i++)
    {
        adj[u[i]].push_back({v[i],w[i]});
        adj[v[i]].push_back({u[i],w[i]});
        mx=max(mx,w[i]);
    }
    n=N;
}
vector<vector<int>>newadj;
vector<int>vs(n+1);
bool check(int node,int parent)
{
    // cout<<node<<" "<<parent<<endl;
    int cnt=0;
    if(vs[node]==true)return 1;
    vs[node]=true;
    for(auto i:newadj[node])
    {
        if(i==parent)continue;
        cnt++;
    }
    if(cnt>1&&parent!=-1)return 1;
    else
    {
        int lol=0;
        for(auto i:newadj[node])
        {
            if(i==parent)continue;
            lol|=check(i,node);
        }
        return lol;
    }
}
bool findy(int node,int y)
{
    vs[node]=true;
    if(node==y)return 1;
    int lol=0;
    for(auto i:newadj[node])
    {
        if(!vs[i])
            lol|=findy(i,y);
    }
    return lol;
}
int getMinimumFuelCapacity(int x, int y) {
    int l=1,r=mx;
    int ans=-1;
    newadj.resize(n+1);
    for(int i=0;i<=n;i++)vs[i]=0;
    while(l<=r){
        int mid=(l+r)/2;
        for(int i=0;i<n;i++)
            for(auto j:adj[i])
                if(j.second<=mid)
                    newadj[i].push_back(j.first);
        int node=-1;
        // cout<<"HI"<<endl;
        int e=check(x,-1);
        for(int i=0;i<n;i++)vs[i]=0;
        int ee=findy(x,y);
        if(e&&ee)
        {
            ans=mid;
            r=mid-1;
        }
        else l=mid+1;
        for(int i=0;i<n;i++)
        {
            vs[i]=0;
            newadj[i].clear();
        }
    }
    return ans;
}

Compilation message

swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:66:13: warning: unused variable 'node' [-Wunused-variable]
   66 |         int node=-1;
      |             ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 3 ms 580 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Runtime error 82 ms 19756 KB Execution killed with signal 6
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Runtime error 61 ms 23856 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 3 ms 580 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 576 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Runtime error 4 ms 872 KB Execution killed with signal 6
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 3 ms 580 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 4 ms 348 KB Output is correct
10 Runtime error 82 ms 19756 KB Execution killed with signal 6
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 3 ms 580 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Runtime error 82 ms 19756 KB Execution killed with signal 6
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 3 ms 580 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 4 ms 348 KB Output is correct
10 Runtime error 82 ms 19756 KB Execution killed with signal 6
11 Halted 0 ms 0 KB -