QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#757514#1774. Customs Controlsosky123456WA 0ms12348kbC++141.8kb2024-11-17 09:09:422024-11-17 09:09:43

Judging History

你现在查看的是最新测评结果

  • [2024-11-17 09:09:43]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:12348kb
  • [2024-11-17 09:09:42]
  • 提交

answer

#include <bits/stdc++.h>
using ll = long long ; 
using ull = unsigned long long ; 
using namespace std;
#define pii pair<int,int> 
#define all(x) x.begin() , x.end() ; 
const int maxn = 2e5 + 100;
int n , m , k , t[maxn]; 
int a[maxn] , b[maxn] , dis[maxn] , vis[maxn] , id[maxn]; 
vector<int> g[maxn] ; 
string solve() {
    // int ok = 0 ; 
    for(int i = 1 ; i <= m ; ++i) {
        g[a[i]].push_back(b[i]) ;
        if(a[i] == 1 && b[i] == n) {
            if (k >= 2) return "U" + string(k - 2, 'U') + string(n - k, 'P') + "U";
            if (n - k >= 2) return "P" + string(k, 'U') + string(n - k - 2, 'P') + "P";
            return "impossible";
        }
    }
    priority_queue<pii , vector<pii> , greater<pii> > q  ;
    memset(dis,0x3f,sizeof dis) ; 
    const int inf = dis[0] ; 
    dis[1] = t[1]  ;
    q.push({t[1] , 1}) ;
    while(!q.empty()) {
        int u = q.top().second ; q.pop() ; 
        for(int v : g[u]) {
            // int v = tmp.first , w = tmp.second ; 
            if(dis[v] > dis[u] + t[v]) {
                dis[v] = dis[u] + t[v] ; 
            }  
        }
    }
    dis[1] = -inf ; dis[n] = inf ;
    iota(id + 1 , id + 1 + n , 1) ; 
    sort(id + 1 , id + 1 + n , [&](int x,int y) {
        return dis[x] < dis[y] ; 
    }); 
    string ans(n , '!') ;
    for(int i = 1 ; i <= n ; ++i) 
        ans[id[i] - 1] = (i <= k? 'U' : 'P') ;  
    return ans ; 
}
signed main() {
    ios::sync_with_stdio(false) ; 
    cin.tie(nullptr) , cout.tie(nullptr) ; 
    cin >> n >> m >> k ; 
    for(int i = 1 ; i <= n ; ++i) 
        cin >> t[i] ; 
    for(int i = 1 ; i <= m ; ++i) {
        cin >> a[i] >> b[i] ; 
        if(a[i] > b[i]) swap(a[i] , b[i]) ; 
    }
    // return 0 ; 
    string ans = solve() ; 
    cout << ans << '\n' ; 
    return 0 ;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 12348kb

input:

5 10 2
1 1 1 1 1
3 4
5 4
3 1
4 1
3 5
2 1
2 4
2 5
1 5
2 3

output:

UPPPU

result:

wrong answer invalid character