Submission #1110686

# Submission time Handle Problem Language Result Execution time Memory
1110686 2024-11-10T07:54:19 Z Ciprian Colors (RMI18_colors) C++14
15 / 100
74 ms 848 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long 
 
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin>>t;
    for(int i=0; i<t; i++){
        int n,m;
        cin>>n>>m;
        vector<int> adj[n+3], deg(n+3), a(n+2), b(n+1);
        for(int j=1; j<=n; j++){
            cin>>a[j];
            
        }for(int j=1; j<=n; j++){
            cin>>b[j];
            
            
        }bool check=true;
        for(int j=1; j<=n; j++){
        
            if(b[j]>a[j]){
                check=false;
        
            }
            
        }
        for(int j=0; j<m; j++){
            int u,v;
            cin>>u>>v;
            adj[u].push_back(v);
            adj[v].push_back(u);
            deg[u]++;
            deg[v]++;
            
        }int r=0;
        for(int j=1; j<=n; j++){
            if(deg[j]>1){
                r=j;
                break;
            }
        }if(r==0)r=1;
        set<int> c;
        c.insert(a[r]);
        for(int j=1; j<=n; j++){
            if(j!=r){
                if(a[j]<=a[r] &&b[r]<=a[j]){
                    c.insert(a[j]);
                }
            }
        }if(!check){
            cout<<0<<endl;
        }else if(m==n-1){
            bool res=true;
            for(int j=1; j<=n; j++){
                
                    if(a[j]!=b[j]){
                        if(c.find(b[j])==c.end()){
                            res=false;
                            break;
                        }
                    }
                
            }cout<<res<<endl;
        }
    }
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 38 ms 336 KB Output is correct
2 Correct 12 ms 848 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 336 KB Output is correct
2 Correct 12 ms 848 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Incorrect 39 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 74 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 336 KB Output is correct
2 Correct 12 ms 848 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Incorrect 31 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -